Created
October 11, 2017 22:35
-
-
Save deadlybulb/0c964948db86c316895f4700679e170e to your computer and use it in GitHub Desktop.
Ways to parse EveKit dates with Java 8 time classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.*; | |
import java.time.format.*; | |
public class Test { | |
public static final String testDateOne = "2016-09-27T17:20:23.344Z"; | |
public static final String testDateTwo = "292278994-08-17T07:12:55.807Z"; | |
public static void main(String[] argv) { | |
// Option 1 - truncate | |
System.out.println(ZonedDateTime.parse(testDateOne.substring(testDateOne.length() - 24), DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"))); | |
System.out.println(ZonedDateTime.parse(testDateTwo.substring(testDateTwo.length() - 24), DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"))); | |
// Option 2 - use optional content to do the same thing | |
System.out.println(ZonedDateTime.parse(testDateOne, DateTimeFormatter.ofPattern("['29227']yyyy-MM-dd'T'HH:mm:ss.SSSX"))); | |
System.out.println(ZonedDateTime.parse(testDateTwo, DateTimeFormatter.ofPattern("['29227']yyyy-MM-dd'T'HH:mm:ss.SSSX"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment