【发布时间】:2021-11-05 03:00:32
【问题描述】:
我得到一个格式为“20210908094049.884Z”的时间戳。这是 LDAP 对象的最后修改时间戳。我使用 Spring Boot Ldap。我不知道如何在像 dd.MM.yyyy HH:mm 这样的日期时间解析这个字符串。
谁能帮帮我?
【问题讨论】:
-
格式好像是
YYYYmmddHHMMSS.sssZ。 -
@AndyTurner 更像
yyyyMMddHHmmss.SSS -
@SenNoRikyu 您在 UTC+2 时区吗?
-
这能回答你的问题吗? Parsing and formatting LocalDate with unnecessary time and timezone。我知道这个问题并不相同,但它是关于解析 LDAP 时间戳的,所以也许你可以从那里的答案中得到你需要的东西并根据你的需要进行修改。
-
我建议你不要使用
SimpleDateFormat和Date。这些类设计不佳且早已过时,尤其是前者,尤其是出了名的麻烦。而是使用OffsetDateTime和/或Instant和DateTimeFormatter,均来自java.time, the modern Java date and time API。
标签: java spring-boot date parsing timestamp