我有以下代码片段,它根据格式将毫秒转换为日期。我使用的是 Joda-time 2.3。
final Long currentMs = new DateTime().getMillis());
DateTimeFormatter currentMsTimeFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
DateTime dt = currentMsTimeFormat.parseDateTime(String.valueOf(currentMs));
System.out.println(dt.toString());
当我运行该程序时,出现以下错误:
java.lang.IllegalArgumentException: Invalid format: "1455711149006" is malformed at "9006"
其中 1455711149006
是 currentMs
的值。
最佳答案
有一个constructor for DateTime
从 EPOCH 开始需要几毫秒。所以你可能想要:
new DateTime(currentMs);
关于java - 在 Joda 中将毫秒转换为日期时间格式时出现解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35456595/