Skip to content

Instantly share code, notes, and snippets.

@koush
Created October 1, 2010 21:38
Show Gist options
  • Save koush/606905 to your computer and use it in GitHub Desktop.
Save koush/606905 to your computer and use it in GitHub Desktop.
public static GregorianCalendar getSynchronizedTime() {
// this time zone is the local time zone
GregorianCalendar greg = new GregorianCalendar();
// find the offset from GMT and adjust accordingly.
// server is in GMT
int offset = greg.getTimeZone().getOffset(greg.getTimeInMillis());
greg.add(GregorianCalendar.MILLISECOND, -offset);
return greg;
}
public static String generateTimestamp()
{
SimpleDateFormat dateFormatter = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
GregorianCalendar greg = getSynchronizedTime();
return dateFormatter.format(greg.getTime());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment