Created
December 7, 2010 21:30
-
-
Save amolbrid/732443 to your computer and use it in GitHub Desktop.
snippet to convert date/time in any timezone to EST
This file contains hidden or 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 Calendar convertTimeToEST(long timeInMillSec) { | |
| Calendar cal = Calendar.getInstance(); | |
| TimeZone tz = cal.getTimeZone(); | |
| cal.setTimeInMillis(timeInMillSec); | |
| TimeZone estTz = TimeZone.getTimeZone("America/New_York"); | |
| Calendar estCal = Calendar.getInstance(estTz); | |
| estCal.setTimeInMillis(timeInMillSec); | |
| int tzOffset = tz.getOffset(cal.getTime().getTime()); | |
| int estTzOffset = estTz.getOffset(estCal.getTime().getTime()); | |
| estCal.add(Calendar.MILLISECOND, (Math.abs(tzOffset) - Math.abs(estTzOffset))); | |
| return estCal; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment