Java解析日期字符串中毫秒值的坑
2020-09-28 17:01:41 908
public class Test {
private static void format1() throws ParseException {
String dateStr = "2020-09-29 15:20:33.15";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
System.out.println(format.format(format.parse(dateStr)));
}
private static void format2() throws ParseException {
String dateStr = "2020-09-29 15:20:33.150";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
System.out.println(format.format(format.parse(dateStr)));
}
private static void format3() throws ParseException {
String dateStr = "2020-09-29 15:20:33.015";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
System.out.println(format.format(format.parse(dateStr)));
}
public static void main(String[] args) throws Exception {
format1();
format2();
format3();
}
}