Created
August 24, 2017 16:47
-
-
Save squito/c3b6bb5098650a865b4cf151022ea606 to your computer and use it in GitHub Desktop.
Java timestamp mechanics
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
> scala -Duser.timezone=America/Los_Angeles timestamp.scala | |
Defaul TZ: America/Los_Angeles | |
hours in UTC: 8 | |
TZ offset in hours: -8 |
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
> scala -Duser.timezone=America/New_York timestamp.scala | |
Defaul TZ: America/New_York | |
hours in UTC: 5 | |
TZ offset in hours: -5 |
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
import java.sql.Timestamp | |
import java.util.TimeZone | |
val tz = TimeZone.getDefault(); | |
println(s"Defaul TZ: ${tz.getID()}") | |
val tsString = "1970-01-01 00:00:00" | |
val ts = Timestamp.valueOf(tsString); | |
println(s"timestamp $tsString has millis ${ts.getTime()}") | |
println(s"hours in UTC: ${ts.getTime() / 1000 / 60 / 60}") | |
println(s"TZ offset in hours: ${tz.getOffset(ts.getTime()) / 1000 / 60 / 60}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment