【问题标题】:DateTime parsing exception in javajava中的DateTime解析异常
【发布时间】:2022-12-17 07:59:37
【问题描述】:

我正在使用 API 开发我的移动应用程序。绑定日期时间给我错误 java.time.format.DateTimeParseException:无法解析文本“2022-12-16T00:00:00+03:00”,在索引 19 处找到未解析的文本。请帮我格式化这个奇怪的日期

fun formatDateOfReview(dateOfReview: String?): String? {
    val localDate = LocalDateTime.parse(dateOfReview)
    return localDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"))
}

【问题讨论】:

  • 您的模式使用点作为分隔符,而您的文本使用破折号(包括时间和时区)

标签: java android kotlin


【解决方案1】:
2022-12-16T00:00:00+03:00

那是a combined date-time with a time zone in ISO 8601 format

LocalDateTime.parse(dateOfReview)

LocalDateTime is "A date-time without a time-zone in the ISO-8601 calendar system"(强调)。

请改为use OffsetDateTime

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-13
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 2011-12-08
    • 1970-01-01
    相关资源
    最近更新 更多