首页 > 编程语言 >python3 时间戳转换

python3 时间戳转换

时间:2023-02-09 12:44:05浏览次数:44  
标签:__ -% 转换成 转换 05 时间 time dt 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')
    

  

 

 

标签:__,-%,转换成,转换,05,时间,time,dt,python3
From: https://www.cnblogs.com/dgshubo/p/17104889.html

相关文章