python常用的时间转化
2021/10/29 17:39:27
本文主要是介绍python常用的时间转化,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
经常遇到,记不住,每次都要查,就很烦
- 获取时间戳
- time.time()
- 时间加减:
- datetime.timedelta(hours=8)
- 时间戳 -> datetime:
- datetime.datetime.fromtimestamp(time.time())
- 字符串时间 -> time.struct_time:
- time.strptime("Fri, 29 Oct 2021 08:52:40 GMT", "%a, %d %b %Y %H:%M:%S GMT")
- 字符串时间 -> datetime:
- datetime.datetime.strptime("Fri, 29 Oct 2021 08:52:40 GMT", "%a, %d %b %Y %H:%M:%S GMT")
- time.struct_time -> 时间戳:
- time.mktime(time.struct_time)
- 时间戳 -> time.struct_time:
- time.localtime(time.time())
- datetime -> time.struct_time:
- datetime.datetime(2021, 10, 29, 16, 52, 40).timetuple()
- datetime -> 时间戳:
- datetime.datetime(2021, 10, 29, 16, 52, 40).timestamp()
这篇关于python常用的时间转化的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python