from time import strftime, localtime
date = strftime("%Y-%m-%d %H:%M:%S", localtime())
print(date)
输出结果
2020-01-03 17:50:42
本文介绍了一种使用Python内置的time模块来获取并格式化当前时间的方法。通过strftime函数,可以将时间戳转换为易读的日期和时间格式。
from time import strftime, localtime
date = strftime("%Y-%m-%d %H:%M:%S", localtime())
print(date)
输出结果
2020-01-03 17:50:42

被折叠的 条评论
为什么被折叠?