标签:local datetime date cal 字符 import str time int
import time import datetime # 首先将时间字符串处理成标准的,即将小数位去掉 time_stamp = "2019-04-10 00:30:10.198" .split(‘.‘)[0] # 将字符串转化为时间戳 h = time.mktime(time.strptime(time_stamp, "%Y-%m-%d %H:%M:%S")) # 将时间戳转换为字符串 start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(h-30)) end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(h+30)) # 将时间字符串转化为datetime类型 start_date = datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") # 将时间戳转化为datetime类型 t = datetime.datetime.fromtimestamp(h) print(t,type(t)) print(start_date,type(start_date))
python中时间戳,datetime 和时间字符串之间得转换
标签:local datetime date cal 字符 import str time int
原文地址:https://www.cnblogs.com/chaojiyingxiong/p/10764031.html