Skip to content

Instantly share code, notes, and snippets.

@littlebeeper
Created December 28, 2018 09:02
Show Gist options
  • Save littlebeeper/edb72aaa076893cd6404a726520b2880 to your computer and use it in GitHub Desktop.
Save littlebeeper/edb72aaa076893cd6404a726520b2880 to your computer and use it in GitHub Desktop.
Java format date as GMT
private static String convertToGMT(String epoch) {
Date date = new Date(Long.parseLong(epoch));
String GMT_FORMAT = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(GMT_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
// Calendar calendar = Calendar.getInstance();
// calendar.setTimeInMillis(entityAttribute.toInstant().toEpochMilli());
// calendar.setTimeZone(TimeZone.getTimeZone(entityAttribute.getZone()));
// return calendar;
return dateFormat.format(date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment