python3 时间戳转换

import time

def time_conversion(times):
    # 转换成新的时间格式(2016-05-05 20:28:54)
    dt = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(times))
    print(dt)

def unix_time(dt):
    # 转换成时间数组
    timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
    # 转换成时间戳
    timestamp = int(time.mktime(timeArray))
    print(timestamp)

if __name__ == '__main__':
    time_conversion(1675908338)
    unix_time('2023-02-09 10:05:38')
    

  

 

 

posted @ 2023-02-09 12:39  江戸川のコナン  阅读(15)  评论(0编辑  收藏  举报
……