下面的表达式不能使用。我想转换 2020-05-05T01:01:01.000+05:30
变成 2020-05-05T01:01:01
. 但在此之前,我需要把它解析成LocalDateTime。问题在于 "+00:00 "这部分,不知道该如何格式化。
LocalDateTime.parse("2020-05-05T01:01:01.000+05:30", "yyyy-MM-dd'T'HH:mm:ss.SSS+00:00")
你的输入是日期时间字符串,偏移量为UTC加5小时30分钟,所以直接解析成 "+00:00 "即可。OffsetDateTime
String dateTimeString = "2020-05-05T01:01:01.000+05:30";
OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateTimeString);
然后从中获取LocalDateTime。
offsetDateTime.toLocalDateTime(); //2020-05-05T01:01:01