我使用ThreeTen
模块,当我打印ZonedDateTime.now()
时,我得到。
2019-07-11T22:43:36.564-07:00[America/Los_Angeles]
这是什么格式的?我试过uuuu-MM-dd'T'HH:mm:ss.SSS'Z'
,它说,
org.threeten.bp.format.DateTimeParseException: Text '2019-07-11T22:43:36.564-07:00[America/Los_Angeles]' could not be parsed at index 23
因此,在SSS
之后,'Z'
部分是不正确的。
实现它的正确方式是什么?
这是我的代码:
val pstTime = ZonedDateTime.now(ZoneId.of("America/Los_Angeles")).toString()
val timeFormatter = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSS'Z'")
val mTime = LocalDateTime.parse(pstTime, timeFormatter).toString()
tv_pstTime.text = mTime
我想把它解析成像Tuesday, July 2 5:15:01 P.M.
这样的格式,我该怎么做呢?
发布于 2019-07-12 14:51:48
您可以使用DateTimeFormatter.ofPattern("....")
。在.ofPattern("....")
中,你可以拥有任何你想要的模式。
如下所示:
val result = ZonedDateTime.now(ZoneId.of("America/Los_Angeles"))
.format(DateTimeFormatter.ofPattern("EEEE, MMMM d HH:mm:ss a"))
输出:Thursday, July 11 23:51:21 PM
https://stackoverflow.com/questions/57000860
复制相似问题