美文网首页
python 时间戳和时间的转换

python 时间戳和时间的转换

作者: beed0c3eb989 | 来源:发表于2017-06-19 15:55 被阅读0次
import time
#字符串时间转换成时间戳
def StrToTimestamp(dt):
    #转换成时间数组
    timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
    #转换成时间戳
    timestamp = int(time.mktime(timeArray))
    return timestamp

#字符串格式的更改
def ChangeTimestyle(dt):
    #转化成时间数组
    timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
    #用时间数组转化格式
    otherTimestyle = time.strftime("%Y/%m/%d %H:%M:%S", timeArray)
    return otherTimestyle

#时间戳转换为指定格式的日期
def TimestampToTime(timestamp):
    #转化成时间数组
    timeArray = time.localtime(timestamp)
    timestyle = time.strftime("%Y/%m/%d %H:%M:%S", timeArray)
    return timestyle

相关文章

网友评论

      本文标题:python 时间戳和时间的转换

      本文链接:https://www.haomeiwen.com/subject/loogqxtx.html