Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.TimeZone
- def updateTimeZone(zone: String) = {
- System.setProperty("user.timezone", zone);
- TimeZone.setDefault(TimeZone.getTimeZone(zone))
- }
- // Set timezone to Pacific Standard, where -- at least for now --
- // daylight savings is in effect
- updateTimeZone("PST")
- java.sql.Timestamp.valueOf("2019-03-10 01:00:00")
- // should result in: java.sql.Timestamp = 2019-03-10 01:00:00.0
- java.sql.Timestamp.valueOf("2019-03-09 02:00:00") // 2 AM
- // should result in: java.sql.Timestamp = 2019-03-09 02:00:00.0
- java.sql.Timestamp.valueOf("2019-03-10 02:00:00")
- // should result in: java.sql.Timestamp = 2019-03-10 03:00:00.0 - 3 AM, not 2 AM as per input !
- // Let's now move to Japan time, where day light savings rules are not followed
- updateTimeZone("Asia/Tokyo")
- java.sql.Timestamp.valueOf("2019-03-10 01:00:00")
- // should result in: java.sql.Timestamp = 2019-03-10 01:00:00.0
- java.sql.Timestamp.valueOf("2019-03-09 02:00:00") // 2 AM
- // should result in: java.sql.Timestamp = 2019-03-09 02:00:00.0
- java.sql.Timestamp.valueOf("2019-03-10 02:00:00")
- // should result in: java.sql.Timestamp = 2019-03-10 03:00:00.0 - Doesn't skip 1 hour to 3 AM !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement