python 1970年以前 字符串转换时间戳
代码1
from datetime import datetime result = '1970-01-01 07:00:00' time_1 = '1966-07-17 06:03:00' if time_1 > result: array = time.strptime(time_1, "%Y-%m-%d %H:%M:%S") publishTime = int(time.mktime(array)) * 1000 print(publishTime) else: time_1_struct = datetime.strptime(time_1, "%Y-%m-%d %H:%M:%S") time_2_struct = datetime.strptime(result, "%Y-%m-%d %H:%M:%S") seconds = (time_2_struct - time_1_struct).seconds print('-' + str(seconds))
代码2
from datetime import datetime epoch = datetime(1970, 1, 1) t = datetime(1956, 3, 2) diff = t - epoch print(diff.days * 24 * 3600 + diff.seconds)
如果觉得对您有帮助,麻烦您点一下推荐,谢谢!
好记忆不如烂笔头
好记忆不如烂笔头