python时间相关

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博客

posted @   张浩东zhanghad  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
历史上的今天:
2020-05-08 c/c++随机数
点击右上角即可分享
微信分享提示