python 时间转换

1. timestamp => 固定格式
ts = 1544704784
time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(ts))

2. 通过replace 来求某时刻的timestamp
now = datetime.datetime.now()
earlymon = now.replace(day=1, hour=0, minute=0, second=0)
earlymonts = int(time.mktime(earlymon.timetuple()))

3. 未完待续 ...



参考:python time, datetime, string, timestamp相互转换

原文地址:https://www.cnblogs.com/stellar/p/10116290.html