guest@linuxthings: ~/guides/dates.md

guest@linuxthings:~/guides$ man dates

Dates & Time

date                       # Print current date/time
date +%F                   # Print YYYY-MM-DD
date +%T                   # Print HH:MM:SS
date "+%A %d %B %Y"        # e.g. Tuesday 17 November 2026
date +%s                   # Seconds since 1 Jan 1970 (Unix time)
date -u                    # Current time in UTC
date -I                    # ISO 8601 date
cal                        # Print calendar for current month
cal -3                     # Previous, current and next month
cal 2025                   # Print calendar for year
cal 8 2025                 # A specific month

Format Codes

Code

Meaning

Example

%Y / %y

Year, 4 / 2 digits

2026 / 26

%m

Month number

11

%B / %b

Month name, full / short

November / Nov

%d

Day of month

17

%A / %a

Weekday, full / short

Tuesday / Tue

%u

Day of week, 1 = Monday

2

%j

Day of the year

321

%H:%M:%S

Hour, minute, second (24-hour)

14:05:09

%I %p

Hour (12-hour) and AM/PM

02 PM

%Z / %z

Time zone name / offset

GMT / +0000

%s

Seconds since the Unix epoch

1794924309

%F / %T

Shortcuts for %Y-%m-%d / %H:%M:%S

2026-11-17 / 14:05:09

Date Arithmetic (GNU date)

date -d tomorrow           # Tomorrow at the current time
date -d "next friday"      # Natural-language dates
date -d "3 days ago" +%F   # A date in the past
date -d "2026-12-25" +%A   # Which weekday is Christmas?
date -d @1700000000        # Convert Unix time to a readable date
date -r file.txt           # Last-modified time of a file
TZ=Asia/Tokyo date         # The time in another time zone

A common use is timestamped filenames:

tar -czf backup-$(date +%F).tar.gz ~/Documents
cp app.log app-$(date +%Y%m%d-%H%M).log

System Clock and Time Zone (timedatectl)

timedatectl                       # Local time, UTC, time zone and sync status
timedatectl list-timezones | grep -i berlin
sudo timedatectl set-timezone Europe/Berlin
sudo timedatectl set-ntp true     # Keep the clock synced over the network

Time zones use the Region/City form shown by list-timezones. If you need to set the time by hand with timedatectl set-time, turn NTP sync off first.

Timing Commands

time make                  # How long a command takes (real, user, sys)
sleep 90                   # Pause 90 seconds (also 5m, 2h)
uptime -s                  # When the system booted

guest@linuxthings:~/guides$