在JAVA中,如何格式化AM-PM格式的时间?

该示例使用SimpleDateFormat(“HH-mm-ss a”)构造函数和SimpleDateFormat类的sdf.format(date)方法格式化时间。

package com.yiibai;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeAmPm {
    public static void main(String[] args) {
        Date date = new Date();
        String strDateFormat = "HH:mm:ss a";
        SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
        System.out.println(sdf.format(date));
    }
}
Java

执行上面示例代码,得到以下结果 -

05:33:06 上午

相关文章:

  • 2023-01-09
  • 2021-12-15
  • 2021-11-23
  • 2022-12-23
  • 2021-07-15
  • 2022-02-17
猜你喜欢
  • 2022-12-23
  • 2021-09-07
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案