What’s Delorean?
Delorean是Python里一个很方便的日期时间库,可以让人更简单省心的获取时间,不必受困于时间模块中的各种问题。
Delorean是电影《回到未来》里的那辆极为炫酷的鸥翼汽车,采用这部电影里的非常具有代表性的汽车的名字作为库名,作者估计也是想表达使用这个库能让你在时空里任意遨游,没有掣肘。
项目地址:https://delorean.readthedocs.io/en/latest/
Delorean: Time Travel Made Easy.
接下来看看具体的实现:
Getting Started
安装Delorean
pip3 install Delorean
导入
from delorean import Delorean
使用
d = Delorean()
print(d)
Delorean(datetime=datetime.datetime(2018, 5, 10, 8, 52, 23, 560811), timezone='UTC')
``这里默认的是UTC时间``
转换为国内时区
d = d.shift("Asia/Shanghai")
print(d)
Delorean(datetime=datetime.datetime(2018, 5, 10, 16, 52, 23, 560718), timezone='Asia/Shanghai')
当然也可以打印datetime、date
print(d.datetime, d.date)
2018-05-10 16:58:22.397155+08:00 2018-05-10