【发布时间】:2019-02-19 02:47:25
【问题描述】:
我正在尝试将数字字符串值转换为日期。
我的代码是
String input = "1537011000";
Date d = new SimpleDateFormat("ddMMMM").parse(input);
String output = new SimpleDateFormat("MMMM dd, yyyy").format(d);
System.out.println("output = " + output);
**但我无法转换。我收到了Exception:
Unparseable date: "1537011000"
预计结果是 9 月 15 日
【问题讨论】:
-
“1537011000”代表什么?自某个起点以来的(毫秒)秒数?自 1970 年 1 月 1 日以来看起来像秒(而不是毫秒)
-
我建议你避免使用
SimpleDateFormat类。它不仅过时了,而且出了名的麻烦。今天我们在java.time, the modern Java date and time API 中做得更好。