Created
March 31, 2018 16:55
-
-
Save amostajo/c7ae46e296221c1f0f2ffea1cf6360bc to your computer and use it in GitHub Desktop.
Android's date time value fix based on timezone differences.
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
// Needed | |
import java.util.Calendar; | |
import java.util.TimeZone; | |
// Initialize calendar instance and set your datetime value | |
Calendar cal = Calendar.getInstance(); | |
cal.setTimeInMillis(dateTimeValue); | |
// Initialize timezone with your timezone value | |
TimeZone tz = TimeZone.getTimeZone("America/New_York"); | |
// Get the correct time | |
// Time - TimeZone difference - TimeZone Daylight Savings difference | |
long fixedDateTime = cal.getTimeInMillis() - tz.getRawOffset() - tz.getDSTSavings(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment