在Docker中运行关于时间的代码发现总是出现特别奇怪的问题,比如:应该白天出现的时间总是显示在半夜。通过命令date发现,时区不是当前所在时区。查阅资料后,一个适合自己的时区修改方式如下:
dpkg-reconfigure tzdata
初始时大概会报错:需要安装tzdata安装包
/usr/sbin/dpkg-reconfigure: tzdata is not installed
安装之后,便可以根据提示,选择自己想要设置的时区。比如我选择北京时间(上海):
Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time
zones in which they are located.
1. Africa 2. America 3. Antarctica 4. Australia 5. Arctic 6. Asia 7. Atlantic 8. Europe 9. Indian 10. Pacific 11. SystemV 12. US 13. Etc
Please select the city or region corresponding to your time zone.
1. Aden 11. Baku 21. Damascus 31. Hong_Kong 41. Kashgar 5