使用time输出时间戳
import time
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
# 输出 2016-03-20 11:45:39
print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
# 输出 Sat Mar 28 22:24:24 2016
# 将 时间字符串 转换为 时间戳
a = "Sat Mar 28 22:24:24 2016"
print(time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))
# 1459175064.0
使用datetime输出时间戳
import datetime
print(datetime.datetime.now())
# 2020-02-12 04:33:00.433974
print(datetime.datetime.now() + datetime.timedelta(hours=8))
# 2020-02-12 12:33:00.433974
参考链接