Java 不可剥夺的日期:“;2018-07-03T01:00:21.000;0000“;无法分析此格式
尝试1: 尝试2:Java 不可剥夺的日期:“;2018-07-03T01:00:21.000;0000“;无法分析此格式,java,simpledateformat,Java,Simpledateformat,尝试1: 尝试2: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+/-HHmm"); format.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = format.parse(createdDate2); 尝试3: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd\'T
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+/-HHmm");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
尝试3:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
这种格式似乎不起作用:
有什么帮助吗?这可能不是您想要的,但是如果时区偏移量是用冒号分隔符写入的,例如
+00:00
则是ISO\u offset\u DATE\u TIME
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
这可能不是您想要的,但如果时区偏移量使用冒号分隔符写入,例如
+00:00
,则是ISO\u偏移量\u日期\u时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
您使用
SimpleDateFormat
、TimeZone
和Date
类的具体原因是什么?这些都已经过时很久了,尤其是SimpleDateFormat
非常麻烦。今天,我们有这么多更好的。猜猜,为什么Oracle没有完全弃用Date对象?因为仍然有很多代码使用日期对象……您使用SimpleDateFormat
、TimeZone
和Date
类的具体原因是什么?这些都已经过时很久了,尤其是SimpleDateFormat
非常麻烦。今天,我们有这么多更好的。猜猜,为什么Oracle没有完全弃用Date对象?因为仍然有很多代码使用日期对象…好建议。要将+0000
解析为偏移量,您可以使用偏移量为xx
的格式模式字符串构建DatetimeFormatter
。当我尝试将此字符串解析为字符序列:“2018-07-10T01:00:03.000+0000”时,我收到以下错误:java.time.format.DateTimeParseException:无法在索引处解析文本“2018-07-10T01:00:03.000+0000”23
@NagendraSingh这是因为时区偏移量中没有冒号。建议不错。要将+0000
解析为偏移量,您可以使用偏移量为xx
的格式模式字符串构建DatetimeFormatter
。当我尝试将此字符串解析为字符序列:“2018-07-10T01:00:03.000+0000”时,我收到以下错误:java.time.format.DateTimeParseException:无法在索引处解析文本“2018-07-10T01:00:03.000+0000”23
@NagendraSingh这是因为时区偏移量中没有冒号。