目录
time
time — Time access and conversions — Python 3.10.0 documentation
import time
# 1970-01-01 00:00:00 到现在经过了多少秒
print(time.time())
# 返回一个时间元组
print(time.localtime())
# 时间转字符串
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
# 字符串转时间
print(time.strptime('2021-10-15 15:25:04','%Y-%m-%d %H:%M:%S'))
datetime
datetime — Basic date and time types — Python 3.10.0 documentation
from datetime import datetime
# 当前时间
print(datetime.now())
# 时间转字符串
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
# 字符串转时间
print(datetime.strptime('2017-3-22 15:25:01','%Y-%m-%d %H:%M:%S'))
参考博客
python与时间相关的库_szuhuanggang的博客-CSDN博客
python——time库整理(基础知识+实例) - 知乎 (zhihu.com)
Python datetime模块详解、示例_Steven的博客-CSDN博客_python中的datetime
Python中time模块详解_You_are_my_dream的博客-CSDN博客
python datetime与timestamp_dudu3332的博客-CSDN博客
标签:-%,python,博客,datetime,时间,time,print,相关 From: https://www.cnblogs.com/zhanghad/p/17382188.html