扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

simpledateformat是否支持毫秒级格式化

扬州沐宇科技
2024-06-19 14:12:02
simpledateformat

是的,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。

扫码添加客服微信