Printing a Date in a Different Timezone

Printing dates, or indeed executing any Unix command for a certain timezone is easily done with setting the TZ environment variable.

For your local system, you typically set the timezone in /etc/timezone, but often it's useful to change the timezone just for executing a command or two, such as priting the date in a different country.

To print the date in e.g. Oslo when your local timezone is e.g. 'Asia/Taipei', do (yes on the same line, without any export or the sort):

$ TZ='Europe/Oslo' date

If you had used an export TZ there, the timezone change would have "stuck" longer than just the one date command.

Another good usecase for setting the TZ variable is to make sure calls to the Google Calender CLI work.

Happy coding!


~ /home 🏠 ~ talks 💬 ~ bash ~ craftsmanship ~ db ~ dongxi ~ emacs ~ escenic ~ iam ~ java ~ js ~ language ~ latex ~ ldap ~ life ~ linux ~ llm ~ mac-os-x ~ mt-foo ~ network ~ norsk ~ python ~ quotes ~ running ~ security ~ travel ~ unix ~ various ~ vcs ~ webdesign ~ windows ~ discoveries ~ cv 🧙 ~

Licensed under CC BY Creative Commons License ~ 📡 RSS feed ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🎥 youtube.com/@skybert