时间戳和字符串之间的转化
时间:2020-04-24 17:45:13
收藏:0
阅读:60
参考:https://www.liaoxuefeng.com/wiki/1016959663602400/1017648783851616
1 import datetime
2 def str_to_timestamp(t): 3 t_datetime = datetime.datetime.strptime(t, ‘%Y-%m-%d %H:%M:%S‘) 4 timeStamp = int(datetime.datetime.timestamp(t_datetime)*1000) 5 return timeStamp 6 7 def timestamp_to_str(timestamp): 8 t_str = datetime.datetime.fromtimestamp(timestamp/1000).strftime(‘%Y-%m-%d %H:%M:%S‘) 9 return t_str
t = str_to_timestamp(‘2010-2-5 9:2:2‘) #1265331722000
t1 = timestamp_to_str(1265331722000) #2010-02-05 09:02:02
原文:https://www.cnblogs.com/daiyanxi/p/12768352.html
评论(0)