Skip to content

Instantly share code, notes, and snippets.

@hlship
Created December 8, 2010 20:01
Show Gist options
  • Save hlship/733810 to your computer and use it in GitHub Desktop.
Save hlship/733810 to your computer and use it in GitHub Desktop.
Selection from DateField component that handles parsing the date string to the user's time zone
// Regardless of the timeZone set on the DateFormat, the value is parsed in
// the current default TimeZone. Use the calendar to adjust it out.
Date inDefaultTimeZone = format.parse(value);
Calendar c = Calendar.getInstance(locale);
c.setTime(inDefaultTimeZone);
TimeZone clientZone = timeZoneTracker.getClientTimeZone();
TimeZone defaultZone = TimeZone.getDefault();
long now = System.currentTimeMillis();
int offset = defaultZone.getOffset(now) - clientZone.getOffset(now);
c.add(Calendar.MILLISECOND, offset);
parsedValue = c.getTime();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment