【Python】+数字时间戳转换为指定格式

参考

1、代码:

 1 def date_operation():
 2     # step1:获取当前时间戳(数字形式)
 3     now_time = time.time()
 4 
 5     # step2:将数字形式的时间戳转换为指定的时间格式
 6     tup_time = time.localtime(now_time)
 7     str_time = time.strftime("%Y-%m-%d %H:%M:%S", tup_time)
 8 
 9     # step3:打印验证
10     print(now_time)
11     print(str_time)
12 
13 
14 if __name__ == "__main__":
15     date_operation()

2、输出:

1572246989.9118552
2019-10-28 15:16:29

猜你喜欢

转载自www.cnblogs.com/danhuai/p/11752519.html