Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. ## Python 3.7.3, MacOS 10.14.5
  2.  
  3. ```>>> import time, datetime
  4. >>> epoch = int(datetime.datetime.now().timestamp())
  5. >>> epoch
  6. 1567872682
  7. >>> gmt = time.gmtime(epoch)
  8. >>> gmt.tm_zone
  9. 'UTC'
  10. >>> time.strftime('%Z', gmt)
  11. 'UTC'
  12. >>> time.strftime('%z', gmt)
  13. '-0500'
  14. ```
  15.  
  16. I'm currently at `-0400 (EDT)` and my best guess is that because the `tm_isdst` flag is set to false, it's interpreting my Eastern time zone as it would be when we're no longer on DST.
  17.  
  18. ```>>> gmt
  19. time.struct_time(tm_year=2019, tm_mon=9, tm_mday=7, tm_hour=16, tm_min=11, tm_sec=22, tm_wday=5, tm_yday=250, tm_isdst=0)
  20. ```
  21.  
  22. In my Anaconda install on Windows 7, it's worse (or maybe better: more consistently broken).
  23.  
  24. ## Python 3.7.1, Windows 7
  25.  
  26. ```
  27. >>> gmt.tm_zone
  28. 'UTC'
  29. >>> time.strftime('%Z', gmt)
  30. 'Eastern Standard Time'
  31. >>> time.strftime('%z', gmt)
  32. '-0500'
  33. ```
  34.  
  35. On Amazon Linux, Python 3.6, the system works properly. In fact it addresses another problem with the above: technically UTC isn't a time zone, while GMT is.
  36.  
  37. ## Python 3.6.4, Amazon Linux
  38.  
  39. ```>>> epoch = int(datetime.datetime.now().timestamp())
  40. >>> gmt = time.gmtime(epoch)
  41. >>> gmt.tm_zone
  42. 'GMT'
  43. >>> time.strftime('%Z', gmt)
  44. 'GMT'
  45. >>> time.strftime('%z', gmt)
  46. '+0000'
  47. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement