datetimes
将字符串形式的数据转化为datetime时间对象
import datetimes as dt
import dateutil
dateutil.parser.parse('01/11/2011')
>>>
datetime.datetime(2011, 1, 11, 0, 0)
各种形式都可以 2011/01/11
2011-01-11
2021-JAN-11
当前时间
dt.date.today()
减去/加上一段时间
dt.timedelta(days=n)
days=
, hours=
, minutes=
, seconds=
时间差
t1 = dateutil.parser.parse('01/11/2011')
t2 = dateutil.parser.parse('01/21/2011')
delta_t = t2 - t1
delta_t.days
>>> 10
Document Information
- Author: Zeka Lee
- Link: https://zhekaili.github.io/wiki/python-libs/python-lib-datetimes/
- Copyright: 自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)