当前位置: 首页 > 知识库问答 >
问题:

DateTimeParseException:无法分析索引2处的文本[重复]

高夜洛
2023-03-14
public static void main(String[] args) {
        java.time.format.DateTimeFormatter dtf = java.time.format.DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz");
        String date = "Mon, 10 Sep 2018 23:57:09 UTC";
        System.out.println(dtf.parse(date));
}
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Mon, 10 Sep 2018 23:57:09 UTC' could not be parsed at index 2
    at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
    at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1777)
    at com.sample.binding.bitronvideo.driver.BitronVideoRecordingDriver.main(BitronVideoRecordingDriver.java:448)

谢谢,艾米特

共有1个答案

梁浩
2023-03-14

我没有得到例外。所以检查您的个人资料,我看到您的地区是在德国,所以我尝试了这个,并得到了例外。

    java.time.format.DateTimeFormatter dtf = 
             java.time.format.DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", 
                                                       Locale.GERMANY);
    String date = "Mon, 10 Sep 2018 23:57:09 UTC";
    System.out.println(dtf.parse(date));

德语的shorday是:

短工作日So,Mo,Di,Mi,Do,Fr,Sa

    java.time.format.DateTimeFormatter dtf =
              java.time.format.DateTimeFormatter.ofPattern("EE, dd MMM yyyy HH:mm:ss zzz");
    String date = "Mo, 10 Sep 2018 23:57:09 UTC";
    System.out.println(dtf.parse(date));
    java.time.format.DateTimeFormatter dtf =
           java.time.format.DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", 
                                                         Locale.UK);
    String date = "Mon, 10 Sep 2018 23:57:09 UTC";
    System.out.println(dtf.parse(date));
 类似资料: