无法解析的日期:“2018-08-02T14:24:40.040353”

Unparseable date: "2018-08-02T14:24:40.040353"

我正在尝试将 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, If you are using Java8 you can use java.time API and use the default format of LocalDateTime :

String dateString = "2018-08-02T14:24:40.040353";
LocalDateTime ldt = LocalDateTime.parse(dateString);

ldt.toString():

2018-08-02T14:24:40.040353