Skip to content

Instantly share code, notes, and snippets.

@bmnepali
Created March 20, 2020 06:24
Show Gist options
  • Save bmnepali/1a74bf017a62ef35f10642017d332567 to your computer and use it in GitHub Desktop.
Save bmnepali/1a74bf017a62ef35f10642017d332567 to your computer and use it in GitHub Desktop.
public static Date localToGMT() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmt = new Date(sdf.format(date));
return gmt;
}
public static Date gmttoLocalDate(Date date) {
String timeZone = Calendar.getInstance().getTimeZone().getID();
Date local = new Date(date.getTime() + TimeZone.getTimeZone(timeZone).getOffset(date.getTime()));
return local
}
// You can use DateFormat.parse(String date) instead of new Date(String date) as it is deprecated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment