如何将YMD LDAP时间戳转换为Java中的日期时间?

huangapple go评论63阅读模式
英文:

How can I convert YMD LDAP timestamps to date time in Java?

问题

例如,我有一个日期:20171208181856.0Z,我想使用Java将其转换为日期时间格式。我似乎找不到任何有效的解决方法。

英文:

For instance I have the date as: 20171208181856.0Z and I want to convert it into date time format using java. I don't seem to find any working solutions for it.

答案1

得分: 2

你可以使用输入格式创建 DateTimeFormatter,然后将其解析为 ZonedDateTime 或者 OffsetDateTime

String dateTime = "20171208181856.0Z";

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss.SX");

OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateTime, formatter);

System.out.println(offsetDateTime);
英文:

You can create DateTimeFormatter using input format and parse it into ZonedDateTime or OffsetDateTime

String dateTime = "20171208181856.0Z";

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss.SX");

OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateTime,formatter);

System.out.println(offsetDateTime);

huangapple
  • 本文由 发表于 2020年3月17日 03:35:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/60712199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定