>_ IzzyLab

Hands-on task

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

Convert Unix time to a date (UTC)

easy~3 min

The file /root/ts.txt contains a Unix timestamp (the number of seconds since 1970-01-01, the epoch) — 1700000000. Convert it to a human-readable date in UTC in the format YYYY-MM-DD HH:MM:SS and write the result to /root/out.txt (on a single line, with no timezone in the text). Note: the sandbox's system time zone is Europe/Berlin, not UTC.

What you'll practise:
  • date
  • unix time
  • epoch
  • utc
  • date formatting

Topic breakdown

A Unix timestamp is the number of seconds since the start of the epoch (1970-01-01 UTC); the date utility can take it as input if the number in the -d option is preceded by the @ prefix. By default date prints time in the container's local zone, so UTC requires a separate option. The output format is set by a string of %-codes after + (%Y, %m, %d, %H, %M, %S).

What's checked

  1. UTC date is correct

What it looks like