Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.util.TimeZone
  2.  
  3.  
  4. def updateTimeZone(zone: String) = {
  5. System.setProperty("user.timezone", zone);
  6. TimeZone.setDefault(TimeZone.getTimeZone(zone))
  7. }
  8.  
  9. // Set timezone to Pacific Standard, where -- at least for now --
  10. // daylight savings is in effect
  11. updateTimeZone("PST")
  12.  
  13. java.sql.Timestamp.valueOf("2019-03-10 01:00:00")
  14. // should result in: java.sql.Timestamp = 2019-03-10 01:00:00.0
  15.  
  16. java.sql.Timestamp.valueOf("2019-03-09 02:00:00") // 2 AM
  17. // should result in: java.sql.Timestamp = 2019-03-09 02:00:00.0
  18.  
  19. java.sql.Timestamp.valueOf("2019-03-10 02:00:00")
  20. // should result in: java.sql.Timestamp = 2019-03-10 03:00:00.0 - 3 AM, not 2 AM as per input !
  21.  
  22.  
  23. // Let's now move to Japan time, where day light savings rules are not followed
  24. updateTimeZone("Asia/Tokyo")
  25.  
  26. java.sql.Timestamp.valueOf("2019-03-10 01:00:00")
  27. // should result in: java.sql.Timestamp = 2019-03-10 01:00:00.0
  28.  
  29. java.sql.Timestamp.valueOf("2019-03-09 02:00:00") // 2 AM
  30. // should result in: java.sql.Timestamp = 2019-03-09 02:00:00.0
  31.  
  32. java.sql.Timestamp.valueOf("2019-03-10 02:00:00")
  33. // 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