1. 时间戳转成具体的时间:
已知数字:1614690000
- 首先转换为当地时间
- 然后格式化显示即可
>>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1614690000)) '2021-03-02 21:00:00'
2. 具体时间转换为时间戳
现将时间格式化
>>> import datetime >>> t1 = t.strftime('%Y-%m-%d %H:%M:%S') >>> t1 '2021-03-31 19:32:04' >>> ts1 = time.mktime(time.strptime(t1, '%Y-%m-%d %H:%M:%S')) >>> ts1 1617190324.0 >>> time.mktime(time.strptime("2021-02-26 11:00:00", '%Y-%m-%d %H:%M:%S')) 1614308400.0 >>> time.mktime(time.strptime("2021-02-26 12:00:00", '%Y-%m-%d %H:%M:%S')) 1614312000.0