>_ IzzyLab

Hands-on task

This task is step 10 of the course “Dates and times in the terminal”

Convert time between timezones

medium~7 min

A meeting is scheduled for 2024-06-01 09:00:00 New York time (America/New_York). A colleague in Tokyo (Asia/Tokyo) needs to know what time that is in their local time. Compute it and write the result to /root/tokyo.txt in the format YYYY-MM-DD HH:MM. The sandbox's system time zone is Europe/Berlin, which matches neither of the two.

What you'll practise:
  • date
  • timezones
  • TZ
  • time conversion

Topic breakdown

date has two independent levers for timezones. The zone of the input date is specified right inside the -d string with the TZ="Zone" construct before the date itself — that's how date knows which zone the original moment is given in. The zone of the output is set by the TZ environment variable before the command call itself. By combining both levers in a single call, one and the same moment in time is recomputed from one zone into another.

What's checked

  1. Tokyo time is correct

What it looks like