温馨提示×

simpledateformat是否支持毫秒级格式化

小樊
87
2024-06-19 14:12:02
栏目: 编程语言

是的,SimpleDateFormat支持毫秒级格式化。可以使用“S”表示毫秒部分。例如,使用“SSS”表示三位毫秒数。下面是一个示例代码:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = new Date();
String formattedDate = sdf.format(date);
System.out.println(formattedDate);

这将打印出当前时间的毫秒级格式化字符串,例如:2022-01-01 12:34:56.789。

0