>>> import datetime
>>> import time
>>> int(time.mktime(datetime.date.today().timetuple()))
1299427200
还有更简单的办法么?
>>> import time
>>> int(time.mktime(datetime.date.today().timetuple()))
1299427200
还有更简单的办法么?
|
GordianZMar 8, 2011
1
import time
print int(time.time()) |
|
GordianZMar 8, 2011
2
@Livid oh, sry, didn't notice you need time for the day...
Then probably yours is the easiest way already :( |
|
3
抱歉我没有表述清楚。
是希望获得今天 0 点时候的 timestamp。 |
|
keakonMar 8, 2011 via iPhone
4
貌似用calendar.timegm更好,mktime会返回浮点数,而且时区可能有问题。不过也没什么能简化的。
|
|
diamondtinMar 8, 2011
5
def mid_night_timestamp():
timestamp = int(time.time()) if timestamp % 86400 == 57600: //57600 = 86400 + (60 * 60 * -8) return timestamp else: return timestamp / 86400 * 86400 + (60 * 60 * -8) This is faster :D 不过仅在时区固定的时候有效,替换一下时区offset就可以了。如果在TimeZone aware的环境,需要用tzinfo的offset修改一下。 |