Created
March 20, 2020 06:24
-
-
Save bmnepali/1a74bf017a62ef35f10642017d332567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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