最近在某微信公众号上看到一篇关于Python工具的文章,其中有一个Pendulum管理时间的工具。我照着练习了一下,练习代码如下:
from datetime import datetime
import pendulum
sh = pendulum.timezone('Asia/Shanghai')
shc = pendulum.now()
print('亚洲上海时区当前时间: ', shc)
ny = pendulum.timezone('America/New_York')
nyc = pendulum.now()
print('美国纽约时区当前时间:', nyc)
nyc.add(years = 1)
执行结果如下图:
在windows环境,centos7环境执行结果都一样。发现的问题是:我虽然更改了时区,但是时间显示都一样。不知问题出在哪里?期望得到解答。