我正在尝试将 DateTime 从 C# 解析为 Java。这是来自 java 调用 "2018-08-02T14:24:40.040353"
的字符串。当我尝试解析它时,出现以下错误 Unparseable date: "2018-08-02T14:24:40.040353"
下面是解析日期的方法
public static String dateFormater(String dateFromJSON, String
expectedFormat, String oldFormat) {
SimpleDateFormat dateFormat = new SimpleDateFormat(oldFormat);
Date date = null;
String convertedDate = null;
try {
date = dateFormat.parse(dateFromJSON);
SimpleDateFormat simpleDateFormat = new
SimpleDateFormat(expectedFormat);
convertedDate = simpleDateFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return convertedDate;
}
最佳答案
你的约会对象看起来像 ISO_LOCAL_DATE_TIME
, 如果你使用的是 Java8 你可以使用 java.time API并使用默认格式 LocalDateTime
像这样:
String dateString = "2018-08-02T14:24:40.040353";
LocalDateTime ldt = LocalDateTime.parse(dateString);
ldt.toString():
2018-08-02T14:24:40.040353
关于java - 无法解析的日期 : "2018-08-02T14:24:40.040353",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51726928/