This question already has answers here:
Parsing ISO-8601 DateTime with offset with colon in Java
                                
                                    (4个答案)
                                
                        
                        
                            String date into Epoch time
                                
                                    (4个答案)
                                
                        
                                4个月前关闭。
            
                    
我有这种格式:

2011-10-10T01:45:20+00:00


我尝试使用LocalDateTime.parse("2011-10-10T01:45:20+00:00")

但我得到了错误:

java.time.format.DateTimeParseEception: Text '2011-10-10T01:45:20+00:00' could not be parse, unparsed text found

最佳答案

默认格式化程序为DateTimeFormatter.ISO_LOCAL_DATE_TIME : '2011-12-03T10:15:30',不存在偏移量,

您可以使用将OffsetDateTime用作格式化程序的DateTimeFormatter.ISO_OFFSET_DATE_TIME : '2011-12-03T10:15:30+01:00'类进行解析

OffsetDateTime.parse("2011-10-10T01:45:20+00:00") // print 2011-10-10T01:45:20Z




您仍然可以使用LocalDateTime,但需要指定格式化程序

LocalDateTime.parse("2011-10-10T01:45:20+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); // 2011-10-10T01:45:20





  Oracle Documentation

关于java - 如何用Java解析此日期格式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57561641/

10-11 02:17
查看更多