python当地时间和UTC时间
[*]>>> from datetime import datetime
[*]>>> import time
[*]>>> import calendar as cal
[*]
[*]>>> utc_now = datetime.utcnow() #当地时间
[*]>>> now = datetime.now() #UTC时间
[*]>>> utc_now
[*]datetime.datetime(2015, 3, 14, 2, 52, 37, 796958)
[*]>>> now
[*]datetime.datetime(2015, 3, 14, 10, 52, 44, 930170)
[*]>>> cal.timegm(datetime.timetuple(utc_now)) #UTC时间戳
[*]1426301557
[*]
>>>time.mktime(datetime.timetuple(now))
1426301564.0
[*] # time.mktime(tuple): this function always returns the timestamp in local time
[*]#calendar.timegm(tuple): this returns the UTC timestamp from the supplied time tuple
页:
[1]