14

Since I move around, I need to be to change time-zones frequently. I'm on Arch/Xfce. How can I do that? I've tried right click on the watch on the top panel -> properties -> time settings -> time zone. It didn't work. When I type a time-zone, it's not auto-completing and not showing suggestions. When I enter it, nonetheless and press Ok, the time doesn't change according to a new time-zone.

What's the proper way to do that?

1

3 Answers 3

27

It's as simple as typing in just one command:

timedatectl set-timezone Zone/SubZone

Where you replace Zone/SubZone with correct data. You can obtain list of all available timezones by typing:

timedatectl list-timezones

If you want to have your RTC (hardware clock) using local time, run the following command:

timedatectl set-local-rtc 1

If you prefer your RTC at UTC, use this one:

timedatectl set-local-rtc 0
5
  • now my time is ahead of my previous time by the amount of hours my current time-zone has: so it's +7 of the current time. why?
    – Johshi
    Jul 19, 2016 at 12:57
  • Do you have your RTC set to local or UTC? If it's set to local, then use this command: timedatectl set-local-rtc 1 if otherwise: timedatectl set-local-rtc 0
    – Jakub
    Jul 19, 2016 at 13:41
  • I don't know, how can I check?
    – Johshi
    Jul 19, 2016 at 15:22
  • what's not the matter of what I want, the thing is "timedatectl set-timezone Zone/SubZone" didn't set the time correctly. will timedatectl set-local-rtc help me and how?
    – Johshi
    Jul 19, 2016 at 16:34
  • You can check your real-time clock (RTC) with timedatectl status. I recommend setting it to universal time (UTC) since everything else (including your local time!) is defined as an offset of UTC. Also note that this works beyond just Arch Linux and beyond just XFCE.
    – Adam Katz
    Aug 7, 2017 at 14:04
1

I was surprised how non-trivial this was, so I wrote a script:

tz-set Asia/Bangkok

Or, to pick a timezone from a list:

tz-set

The following script also updates the timezone in:

#!/bin/bash
set -euo pipefail
program=${0##*/} # basename $0

usage () {
    >&2 printf 'Usage: %s [Region/City]\n' "$program"
    >&2 printf 'Set the system timezone\n'
    >&2 printf 'Will run tz-select to pick timezone if none given.\n'
}

# Process arguments
if [[ $# -gt 1 ]]; then  # 0 or 1 arguments only
    usage; exit 1
fi
if [[ $# -eq 0 ]]; then  # no timezone given - prompt
    timezone=$(tzselect)
else
    timezone=$1  # in timedatactl verificaiton we trust
fi

sudo timedatectl set-timezone "$timezone"

# `timedatectl set-timezone` doesn't update `/etc/timezone`
# https://unix.stackexchange.com/q/451709/143394
 <<<"$timezone" sudo tee /etc/timezone &> /dev/null

printf '\ntimedatectl says:\n'
timedatectl

# Update xfce4-panel clock
# https://unix.stackexchange.com/a/227405/143394
if property=$(xfconf-query -c xfce4-panel --list | grep timezone); then
    if [[ $(wc -l <<<"$property") -eq 1 ]]; then # only one clock widget
        xfconf-query -c xfce4-panel -p "$property" -s "$timezone"
        printf '\nUpdated xfce4-panel clock timezone to: %s\n' "$timezone"
    else
        >&2 printf 'Not changing multiple xfce4-panel properties:\n%s\n' "$property"
    fi
fi
1

Simplest solution if you do not know your current timezone

timedatectl set-timezone "$(curl --fail https://ipapi.co/timezone)"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .