Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import time
  2.  
  3. def _d(y, m, d, days=(0,31,59,90,120,151,181,212,243,273,304,334,365)):
  4. # map a date to the number of days from a reference point
  5. return (((y - 1901)*1461)/4 + days[m-1] + d +
  6. ((m > 2 and not y % 4 and (y % 100 or not y % 400)) and 1))
  7.  
  8. def timegm(tm, epoch=_d(1970,1,1)):
  9. year, month, day, h, m, s = tm[:6]
  10. assert year >= 1970
  11. assert 1 <= month <= 12
  12. return (_d(year, month, day) - epoch)*86400 + h*3600 + m*60 + s
  13.  
  14. t0 = time.time()
  15. tm = time.gmtime(t0)
  16.  
  17. print tm
  18.  
  19. print t0
  20. print timegm(tm)
  21.  
  22. ## (1999, 9, 8, 22, 12, 12, 2, 251, 0)
  23. ## 936828732.48
  24. ## 936828732
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement