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相互转换

posted @ 2018-12-13 20:43  Hsinwang  阅读(170)  评论(0编辑  收藏  举报