Created
December 27, 2015 10:58
-
-
Save anehkumar/a95421f5bbecb570de8f 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
Calendar cal = Calendar.getInstance(); | |
long milliDiff = cal.get(Calendar.ZONE_OFFSET); | |
// Getting time Zone | |
String[] ids = TimeZone.getAvailableIDs(); | |
String name = null; | |
for (String id : ids) { | |
TimeZone tz = TimeZone.getTimeZone(id); | |
if (tz.getRawOffset() == milliDiff) { | |
// Found a match. | |
name = id; | |
break; | |
} | |
} | |
System.out.println(name); | |
//current date time According to GMT 00 | |
Calendar call = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
Date currentLocalTime = call.getTime(); | |
DateFormat date = new SimpleDateFormat("dd-MM-yyy HH:mm:ss"); | |
date.setTimeZone(TimeZone.getTimeZone("GMT")); | |
String localTime = date.format(currentLocalTime); | |
System.out.println(localTime); | |
//current date time according to time zone | |
TimeZone tz = TimeZone.getTimeZone(name); | |
SimpleDateFormat destFormat = new SimpleDateFormat("dd-MM-yyy HH:mm:ss"); | |
destFormat.setTimeZone(tz); | |
String result = destFormat.format(currentLocalTime); | |
System.out.println(result); | |
DateFormat dfm = new SimpleDateFormat("dd-MM-yyy HH:mm:ss"); | |
try { | |
Date unixtime = dfm.parse(result); | |
Date NowDate = dfm.parse(localTime); | |
String timePassedString = String.valueOf(getRelativeTimeSpanString(NowDate.getTime(), unixtime.getTime(), DateUtils.MINUTE_IN_MILLIS)); | |
System.out.println(timePassedString); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment