有时候跑程序中需要获取当时的时间,Python中只要三行代码搞定
导入 time 包,获取此刻的时间戳,然后格式化为我们需要的格式。
import time
now = time.localtime()
print(now)
format_now = time.strftime('%Y/%m/%d %H:%M:%S', now)
print(format_now)
输出如下:
简要记录一下,以后可能会用到。
有时候跑程序中需要获取当时的时间,Python中只要三行代码搞定
导入 time 包,获取此刻的时间戳,然后格式化为我们需要的格式。
import time
now = time.localtime()
print(now)
format_now = time.strftime('%Y/%m/%d %H:%M:%S', now)
print(format_now)
输出如下:
简要记录一下,以后可能会用到。