平时使用Python时,经常会在时间戳(一个整型)与时间之间进行互转。这里写了段代码,表示两者互转的方法,大家感受一下~~
print "timestamp to time:"
timestamp = 1372759811
import time
print time.strftime('%Y-%m-%d %X', time.localtime(timestamp))
print "============================"
print "time to timestamp"
import datetime
dateC = datetime.datetime.now()
timestamp = time.mktime(dateC.timetuple())
print "python timestamp:", timestamp