Home / Alt manpages / org.freedesktop.timedate1(5)

  • org.freedesktop.timedate1(5)
  • File format
  • linux

Change Timezone and NTP Settings via org.freedesktop.timedate1

A batch job on the wrong timezone quietly ships wrong timestamps for months, so change it deliberately, not by editing symlinks. This guide inspects systemd-timedated over the system bus, lists valid timezones, and makes a controlled timezone change when you genuinely need one. Allow about fifteen minutes.

The examples match the installed systemd 255 interface described by org.freedesktop.timedate1(5). You need a shell, the gdbus utility, and a running system bus with systemd-timedated available. Inspection is normally unprivileged; changing time settings can need polkit authentication and should be treated as an administrative operation.

1. Confirm the installed interface

Start with the exact object and service names. This is read-only:

$ dpkg-query -W -f='${Package} ${Version}\n' systemd
systemd 255.4-1ubuntu8.17
$ gdbus introspect --system \
    --dest org.freedesktop.timedate1 \
    --object-path /org/freedesktop/timedate1

Your package revision may differ. The output should include the org.freedesktop.timedate1 interface, methods such as SetTimezone and ListTimezones, and read-only properties including Timezone, LocalRTC, NTP and NTPSynchronized.

Checkpoint: if gdbus cannot connect to the system bus, stop there. A container, rescue environment or unusual test shell may not have one. Do not swap --system for --session: timedated is a system service, not a per-user one.

2. Read the current state

Properties come through the standard D-Bus properties interface. This asks for the configured timezone without changing anything:

$ gdbus call --system \
    --dest org.freedesktop.timedate1 \
    --object-path /org/freedesktop/timedate1 \
    --method org.freedesktop.DBus.Properties.Get \
    org.freedesktop.timedate1 Timezone
(<string 'Europe/London'>,)

The value is host-specific. The first item is a D-Bus variant wrapping the string, so do not parse the angle brackets as part of the timezone name. For a broader, human-readable check, timedatectl reads the same service:

$ timedatectl show --no-pager \
    -p Timezone -p LocalRTC -p CanNTP -p NTP \
    -p NTPSynchronized -p TimeUSec -p RTCTimeUSec
Timezone=Europe/London
LocalRTC=no
CanNTP=yes
NTP=yes
NTPSynchronized=yes

Clock values and synchronisation state change between commands, so treat that as an example shape rather than fixed output. LocalRTC=no means the hardware clock is kept in UTC, the recommended arrangement. LocalRTC=yes means it is kept in local time, which interacts badly with daylight-saving changes.

3. List valid timezone names

Do not guess an identifier or copy a desktop display name. Ask timedated for names this installation actually knows:

$ gdbus call --system \
    --dest org.freedesktop.timedate1 \
    --object-path /org/freedesktop/timedate1 \
    --method org.freedesktop.timedate1.ListTimezones
(['Africa/Abidjan', 'Africa/Accra', ..., 'UTC'],)

The exact order and contents depend on the installed timezone data. Pick one exact value, such as Europe/London, Europe/Paris or UTC, only after you have seen it in your own output.

Tip: to test a candidate without printing the whole list, use the local zoneinfo table instead:

$ grep -F 'Europe/London' /usr/share/zoneinfo/zone.tab
GB	+5130-0007	Europe/London

That is still only a lookup. It does not touch the clock, RTC or timezone setting.

4. Change the timezone deliberately

Warning

The next call changes persistent system configuration. It changes what local time means to applications and, if the RTC is set to local time, updates the RTC to match. Record the current value first so you can undo it.

$ OLD_TZ=$(timedatectl show --no-pager --value -p Timezone)
$ printf 'Current timezone: %s\n' "$OLD_TZ"
Current timezone: Europe/London
$ gdbus call --system --interactive \
    --dest org.freedesktop.timedate1 \
    --object-path /org/freedesktop/timedate1 \
    --method org.freedesktop.timedate1.SetTimezone \
    'Europe/Paris' true
()

Replace Europe/Paris with a value from the list you actually pulled. The final true is the method's interactive boolean: it lets polkit prompt for authentication if policy requires it. Without it, a caller lacking permission gets a polkit error instead of a prompt.

Do not put an untrusted string directly into a shell command. If a script supplies the timezone, validate it against ListTimezones first and pass it as one quoted argument. Avoid changing the timezone mid-batch-job when its logs or deadlines depend on local time.

5. Verify and recover

Read the property again after the call. A successful method return is nice, but the read-back is the actual checkpoint that confirms the daemon now reports what you asked for:

$ gdbus call --system \
    --dest org.freedesktop.timedate1 \
    --object-path /org/freedesktop/timedate1 \
    --method org.freedesktop.DBus.Properties.Get \
    org.freedesktop.timedate1 Timezone
(<string 'Europe/Paris'>,)

Recovery: undo with the value you captured earlier. This is another state-changing command and may prompt for authentication:

$ gdbus call --system --interactive \
    --dest org.freedesktop.timedate1 \
    --object-path /org/freedesktop/timedate1 \
    --method org.freedesktop.timedate1.SetTimezone \
    "$OLD_TZ" true
()

If the shell holding OLD_TZ is gone, pull the old value from your change record or pick a verified value from ListTimezones. Never use an empty value as a shortcut.

6. Know the safety boundaries on the other methods

  • SetTime takes microseconds since 1 January 1970 UTC, either as an absolute time or a relative offset. A mistaken integer can move the system clock far into the past or future, so get the value from a trusted time source and test the calling code before touching a live host.
  • SetLocalRTC chooses UTC or local time for the hardware clock. Its fix_system argument sets the correction direction: true reads the RTC into the system clock, false writes the system time to the RTC. The manpage recommends UTC and reserves the first choice for installers or live media where the RTC is more trustworthy.
  • SetNTP enables or disables network time sync using the selected systemd sync service, and can start or stop that service. Treat it as a service-disrupting administrative change: check CanNTP and record the existing NTP value first. NTPSynchronized reports kernel synchronisation, which is not the same thing as the service being enabled.

The interactive argument controls whether polkit may prompt for credentials on the changing methods. ListTimezones needs no privilege at all. If a privileged call fails, go check the polkit action and current policy rather than loosening the D-Bus call.

Done means

  • Confirmed the service, object path and installed systemd interface.
  • Read the current timezone and told UTC RTC mode apart from local RTC mode.
  • Selected a timezone from the daemon's own list, not a guess.
  • Treated SetTimezone, SetTime, SetLocalRTC and SetNTP as state-changing operations.
  • Verified the change by reading the property back and kept a recovery value.