0
  String current = "07:00:00.160"

  DateFormat df2 = new SimpleDateFormat("HH:mm:ss.SSS"); 

  DateList.add(df2.parse(current));

返回 [Thu Jan 01 07:00:00 GMT 1970]

我也试过这个

    Date currentdate;
    currentdate = df2.parse(current);
    df2.format(currentdate);
    DateList.add(currentdate);

退货也

[1970 年 1 月 1 日星期四 07:00:00 GMT]

我也尝试过使用df2.setLenient(false);

4

1 回答 1

2

java.time.LocalTime

我建议您使用现代 Java 日期和时间 API java.time 来处理您的时间工作。用于一天中时间的类是LocalTime.

我们甚至不需要指定用于解析字符串的格式化程序,因为它是一天中某个时间的默认格式(也在 ISO 8601 标准中规定)。

    String current = "07:00:00.160";
    LocalTime time = LocalTime.parse(current);
    System.out.println(time);

输出:

07:00:00.160

链接

于 2021-09-11T05:47:33.090 回答