Technical skill

Linux time: current time

Subject: .../LINUX

Read the computer's clock

When you want to know what time it is, date displays the computer's system clock. Its ordinary output follows the machine's local time zone and formatting settings. The commands below show local time, an ISO-formatted timestamp with seconds, and UTC. A time zone changes how the same moment is written, not the moment itself. Include UTC or an offset when comparing records from different places.

date
date --iso-8601=seconds
date -u

The first command uses the current locale's usual format. date --iso-8601=seconds requests a readable timestamp with seconds, and -u asks date to display UTC. These commands render the same system clock using different formatting or time-zone rules. A timestamp without a zone can be ambiguous when copied between systems.

GNU date +%s prints seconds since the Unix epoch, 1970-01-01 00:00 UTC. The number is useful in scripts but not immediately readable as a calendar time. GNU date '+%Y-%m-%d %H:%M:%S %z' includes the local numeric UTC offset. Formatting tokens are case-sensitive; other implementations may support different options.

Check the time zone and synchronization

On a system using systemd, timedatectl status displays local and universal time, the RTC setting, configured time zone, and synchronization information. timedatectl list-timezones shows zone names known to that system. A zone such as Europe/Moscow supplies conversion rules; it does not tick as a separate clock.

If local time looks wrong, compare date -u with date and inspect timedatectl. Correct UTC with an unexpected local display points toward the zone setting. If UTC itself is wrong, check the clock source or synchronization service. timedatectl is specific to systemd; use the available tools on other systems.

The system clock is separate from a file's stored timestamp. stat path reports file metadata such as modification time, which may be old or preserved during a copy. A log may also use a time zone or format selected by its application.

Include enough information to compare events

These GNU date commands print an offset or use UTC:

date '+%Y-%m-%dT%H:%M:%S%:z'
date -u --iso-8601=seconds
TZ=UTC date '+%Y-%m-%dT%H:%M:%S%:z'

The TZ=UTC prefix changes the time zone for that command invocation, not the system-wide setting. GNU supports these formatting options, but similarly named utilities elsewhere can differ. A fixed offset cannot replace a named zone when interpreting historical local time because civil-time rules change.

Clock synchronization status is useful evidence, but it does not tell you how an application formats its logs or which clock source it uses. Compare the same instant in UTC and local output, then inspect the application format and configured zone. Direct clock changes can affect logs, scheduled tasks, certificates, and distributed applications; use the system's documented time service if an adjustment is needed.

Interactive exercises

Materials

Skillsets
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful