- // TODO: Does it really help to store timestamps in seconds rather than ms?
- if (inString != null && !inString.equals(""))
- {
- // Try to parse into a long
- try
- {
- long rawValue = Long.parseLong(inString.trim());
- // check for each format possibility and pick nearest
- long diff1 = Math.abs(SECS_SINCE_1970 - rawValue);
- long diff2 = Math.abs(MSECS_SINCE_1970 - rawValue);
- long diff3 = Math.abs(MSECS_SINCE_1990 - rawValue);
- long diff4 = Math.abs(SECS_SINCE_GARTRIP - rawValue);
-
- // Start off with "seconds since 1970" format
- long smallestDiff = diff1;
- _seconds = rawValue;
- // Now check millis since 1970
- if (diff2 < smallestDiff)
- {
- // milliseconds since 1970
- _seconds = rawValue / 1000L;
- smallestDiff = diff2;
- }
- // Now millis since 1990
- if (diff3 < smallestDiff)
- {
- // milliseconds since 1990
- _seconds = rawValue / 1000L + TWENTY_YEARS_IN_SECS;
- smallestDiff = diff3;
- }
- // Lastly, check gartrip offset
- if (diff4 < smallestDiff)
- {
- // seconds since gartrip offset
- _seconds = rawValue + GARTRIP_OFFSET;
- }
- _valid = true;
- }
- catch (NumberFormatException nfe)
- {
- // String is not a long, so try a date/time string instead
- // try each of the date formatters in turn
- Date date = null;
- for (int i=0; i<ALL_DATE_FORMATS.length && !_valid; i++)
- {
- try
- {
- date = ALL_DATE_FORMATS[i].parse(inString);
- CALENDAR.setTime(date);
- _seconds = CALENDAR.getTimeInMillis() / 1000L;
- _valid = true;
- }
- catch (ParseException e) {}
- }
- }
- }
+ // Set timezone for output
+ TimeZone gmtZone = TimeZone.getTimeZone("GMT");
+ ISO_8601_FORMAT.setTimeZone(gmtZone);
+ ISO_8601_FORMAT_WITH_MILLIS.setTimeZone(gmtZone);
+ DEFAULT_DATETIME_FORMAT.setTimeZone(gmtZone);