@@ -24,11 +24,15 @@ private ParsePrimitiveUtils() {
2424 throw new InstantiationError ("This class must not be instantiated." );
2525 }
2626
27+ // check to see if UTC_WITH_MILLIS_FORMAT should be used.
28+ private static final Pattern UTC_MILLIS_PATTERN = Pattern .compile (".*\\ .[0-9]{3}Z$" );
29+
2730 // timestamps are expected to be in UTC
2831 public final static DateFormat UTC_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" );
32+ public final static DateFormat UTC_WITH_MILLIS_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
2933 public final static DateFormat OFFSET_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssX" );
30- public final static DateFormat NON_UTC_FORMAT = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
31- static DateFormat [] dateFormats = { UTC_FORMAT , OFFSET_FORMAT ,NON_UTC_FORMAT };
34+ public final static DateFormat NON_UTC_FORMAT = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS " );
35+ static DateFormat [] dateFormats = { UTC_FORMAT , UTC_WITH_MILLIS_FORMAT , OFFSET_FORMAT ,NON_UTC_FORMAT };
3236 static {
3337 TimeZone tz = TimeZone .getTimeZone ("UTC" );
3438 for ( DateFormat df : dateFormats ) {
@@ -114,7 +118,11 @@ public static String nonUTCFormat(String s) {
114118 Date parsed = null ;
115119 try {
116120 if (s .endsWith ("Z" )) { // 003Z
117- parsed = UTC_FORMAT .parse (s );
121+ if (UTC_MILLIS_PATTERN .matcher (s ).matches ()) {
122+ parsed = UTC_WITH_MILLIS_FORMAT .parse (s );
123+ } else {
124+ parsed = UTC_FORMAT .parse (s );
125+ }
118126 } else if ( hasTZOffset .matcher (s ).matches ()) {
119127 parsed = OFFSET_FORMAT .parse (s ); // +0600 or -06:00
120128 } else {
0 commit comments