字符串时间转 ZonedDateTime 出现的问题

2018-11-12 22:42:34 +08:00
 twirain
String time = "11 12 21:29:01 +0800 2018";
ZonedDateTime c = ZonedDateTime.parse(time, DateTimeFormatter.ofPattern("MM dd HH:mm:ss xx yyyy"));
System.out.println(c);
		
String time2 = "Nov 12 21:29:01 +0800 2018";
ZonedDateTime b = ZonedDateTime.parse(time2, DateTimeFormatter.ofPattern("MMM dd HH:mm:ss xx yyyy"));
System.out.println(b);

第一个输出为:2018-11-12T21:29:01+08:00

第二个直接抛了异常:Exception in thread "main" java.time.format.DateTimeParseException: Text 'Nov 12 21:29:01 +0800 2018' could not be parsed at index 0

1749 次点击
所在节点    问与答
3 条回复
wdlth
2018-11-12 22:53:00 +08:00
https://repl.it/repls/GlamorousSpecializedGnuassembler

没有发现异常,你是不是输入了全角空格之类的?
OscarUsingChen
2018-11-12 23:44:11 +08:00
Locale 的问题?
twirain
2018-11-13 18:42:14 +08:00
用 eclipse 编的,提示 unknown source,参数也都勾上了,不知道什么问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/507182

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX