#输入为string类型的时间,形如 2020-05-31 00:00:00
#输出为毫秒级别的时间戳
import time
def time2tmstp(time_info):
timeArray = time.strptime(time_info, "%Y-%m-%d %H:%M:%S")
timeStamp = int(time.mktime(timeArray))
timeStamp = int(str(timeStamp) + "000")
return timeStamp
def get_hour(timeStamp):
timeStamp = int(str(timeStamp)[:-3])
timeArray = time.localtime(timeStamp)
return timeArray.tm_hour
def get_day(timeStamp):
timeStamp = int(str(timeStamp)[:-3])
timeArray = time.localtime(timeStamp)
return timeArray.tm_mday
def tmstp2time(timeStamp):
def number_process(data):
if (data < 10):
return "0" + str(data)
else:
return str(data)
timeStamp = int(str(timeStamp)[:-3])
timeArray = time.localtime(timeStamp)
year = timeArray.tm_year
month = timeArray.tm_mon
day = timeArray.tm_mday
hour = timeArray.tm_hour
minute = timeArray.tm_min
sec = timeArray.tm_sec
month = number_process(month)
day = number_process(day)
hour = number_process(hour)
minute = number_process(minute)
sec = number_process(sec )
data = str(year)+"-" + str(month) + "-" + str(day) + " " + str(hour) + ":" + str(minute) + ":" + str(sec)
return data
python 常用的时间戳转换小函数
最新推荐文章于 2024-06-21 13:48:43 发布