Search code examples
javatimestampldapunix-timestamp

How can I convert YMD LDAP timestamps to date time in 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.


Solution

  • 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);