我需要将 dateTime 转换为String
毫秒,并且为此使用 ThreeTenABP,但是OffSetDateTime.parse
无法解析String
用于 ex 的 dateTime。"2020-08-14T20:05:00"
并给出以下例外。
Caused by: org.threeten.bp.format.DateTimeParseException:
Text '2020-09-22T20:35:00' could not be parsed:
Unable to obtain OffsetDateTime from TemporalAccessor:
DateTimeBuilder[, ISO, null, 2020-09-22, 20:35], type org.threeten.bp.format.DateTimeBuilder
我已经搜索了类似的问题,但找不到确切的解决方案。
下面是我在 Kotlin 中使用的代码。
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss",
Locale.ROOT)
val givenDateString = event?.eventDateTime
val timeInMillis = OffsetDateTime.parse(givenDateString, formatter)
.toInstant()
.toEpochMilli()