SHARE
TWEET

Untitled

a guest Oct 12th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.time.*;
  2. import java.time.format.*;
  3.  
  4. public class Test {
  5.     public static final String testDateOne = "2016-09-27T17:20:23.344Z";
  6.     public static final String testDateTwo = "292278994-08-17T07:12:55.807Z";
  7.     public static void main(String[] argv) {
  8.     // Option 1 - truncate
  9.     System.out.println(ZonedDateTime.parse(testDateOne.substring(testDateOne.length() - 24), DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX")));
  10.     System.out.println(ZonedDateTime.parse(testDateTwo.substring(testDateTwo.length() - 24), DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX")));
  11.  
  12.     // Option 2 - use optional content to do the same thing
  13.     System.out.println(ZonedDateTime.parse(testDateOne, DateTimeFormatter.ofPattern("['29227']yyyy-MM-dd'T'HH:mm:ss.SSSX")));
  14.     System.out.println(ZonedDateTime.parse(testDateTwo, DateTimeFormatter.ofPattern("['29227']yyyy-MM-dd'T'HH:mm:ss.SSSX")));
  15.     }
  16. }
RAW Paste Data
Top