小编wat*_*hme的帖子

Java DateTimeFormatter:带GMT日期的DateTimeParseException

我想解析像GMT-日期Wed, 21 Oct 2016 07:28:00 GMTDateTimeFormatterInstant.为了创建模式,我使用了官方文档:DateTimeFormatter

我的代码到目前为止:

String date = "Wed, 21 Oct 2016 07:28:00 GMT";

DateTimeFormatter gmtFormat = DateTimeFormatter.ofPattern("EEE' dd LLL yyyy HH:mm:ss '''");
TemporalAccessor parsed = gmtFormat.parse(date);
Instant a = Instant.from(parsed);

System.out.println(a);
Run Code Online (Sandbox Code Playgroud)

但每次我有这个错误:

Exception in thread "main" java.time.format.DateTimeParseException: Text 'Wed, 21 Oct 2016 07:28:00 GMT' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1777)
Run Code Online (Sandbox Code Playgroud)

在索引0Wed,我使用的EEE代表day-of-week定义,也有代表:Tue; Tuesday; T.

我也尝试过低,大写但不成功.怎么了?我忽略了什么吗?

java exception java-8

4
推荐指数
1
解决办法
413
查看次数

标签 统计

exception ×1

java ×1

java-8 ×1