python解析时间
2021/7/2 20:23:21
本文主要是介绍python解析时间,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
>>> strtime="20210702155822065" >>> strtime2="20210702155821729" >>> from datetime import datetime #字符串解析成datetime >>> datetime.strptime(strtime,"%Y%m%d%H%M%S%f") datetime.datetime(2021, 7, 2, 15, 58, 22, 65000) >>> datetime.strptime(strtime2,"%Y%m%d%H%M%S%f") datetime.datetime(2021, 7, 2, 15, 58, 21, 729000) >>> d1=datetime.strptime(strtime,"%Y%m%d%H%M%S%f") >>> d2=datetime.strptime(strtime2,"%Y%m%d%H%M%S%f") #计算时间差 >>> print d1-d2 0:00:00.336000 >>> print type(d1-d2) <type 'datetime.timedelta'> >>> print type(d1) <type 'datetime.datetime'> #打印时间差,专程微秒级int类型 >>> (d1-d2).seconds 0 >>> (d1-d2).microseconds 336000 >>> type((d1-d2).microseconds) <type 'int'>
这篇关于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