python时间戳和时间字符串的转换

时间:2022-05-05 05:44:02
# -*- coding: utf-8 -*-
# date=2020/3/27
import time
import uuid def getTimestamp_1770():
now_1770 = round(time.time() - 1770) * 1000
return now_1770 def getTimestamp(num):
# 1800为30分钟,1740为29分钟
now_1770 = round(time.time() - num) * 1000
return now_1770 def getTimestamp_1700():
now_1700 = round(time.time() - 1700) * 1000
return now_1700 def getTimestamp_1690():
now_1710 = round(time.time() - 1690) * 1000
return now_1710 def getTimestamp_1680():
now_1720 = round(time.time() - 1680) * 1000
return now_1720 def timeToTimestamp(timeStr):
# 先转换为时间数组
timeArray = time.strptime(timeStr, "%Y-%m-%d %H:%M:%S")
# 转换为时间戳
timeStamp = int(time.mktime(timeArray)) * 1000
# print(timeStamp)
return timeStamp def timestampToTime(timeStamp):
timeArray = time.localtime(timeStamp / 1000)
timeStamp = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
# print(timeStamp)
return timeStamp if __name__ == '__main__':
# a = timeToTimestamp('2020-03-27 13:46:20')
#
# a = getTimestamp_1700()
# p = timestampToTime(a)
# print(p)
print(uuid.uuid1())
pass