1.字符串转时间戳
int(time.mktime(time.strptime("20191001000000", "%Y%m%d%H%M%S")))
2.时间戳转字符串
方法一:
import time
time_now = int(time.time())
time_time = time.strftime(’%Y%m%d%H%M%S’, time.localtime(time_now))
print(time_time)
以上方法要转换的字符串中如果有汉字,则会报转码错误,方法二可解决
方法二
time_now = 1566284145
time_time = time.strftime( ‘%Y{y}%m{m}%d{d} %H:%M’, time.localtime(time_now)).format(y=‘年’, m=‘月’, d=‘日’)
print(time_time)
来源:https://blog.csdn.net/weixin_42345642/article/details/100972736