首页 > 编程语言 > 详细

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

时间:2020-03-27 15:54:39      阅读:65      评论:0      收藏:0      [点我收藏+]
# -*- coding: utf-8 -*-
# date=2020/3/27
import time
def getTimestamp_1770():
now_1770 = round(time.time() - 1770) * 1000
return now_1770
def getTimestamp_1700():
now_1700 = round(time.time() - 1700) * 1000
return now_1700
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)

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

原文:https://www.cnblogs.com/zhangzhaolin/p/12581257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!