Arch/Xfceでタイムゾーンをどのように簡単に変更できますか?

Arch/Xfceでタイムゾーンをどのように簡単に変更できますか?

取締役を頻繁に見ると、時間帯を頻繁に変えなければなりません。私はArch / Xfceを使用しています。どうすればいいですか?トップパネルで時計を右クリック - >プロパティ - >時間設定 - >タイムゾーンを試してみました。動作しません。タイムゾーンを入力するとオートコンプリートされず、提案も表示されません。ただし、入力して「OK」を押すと、新しいタイムゾーンによって時間が変わりません。

これを行う正しい方法は何ですか?

答え1

コマンドを入力するのと同じくらい簡単です。

timedatectl set-timezone Zone/SubZone

領域/サブ領域を正しいデータに置き換える場所です。次のように入力して、利用可能なすべてのタイムゾーンのリストを取得できます。

timedatectl list-timezones

ハードウェアクロック(RTC)に現地時間を使用さ​​せるには、次のコマンドを実行します。

timedatectl set-local-rtc 1

UTC時間でRTCを好む場合は、次のオプションを使用します。

timedatectl set-local-rtc 0

答え2

私はこれがどれほど些細なことに驚いたので、スクリプトを書いた。

tz-set Asia/Bangkok

または、リストからタイムゾーンを選択してください。

tz-set

次のスクリプトはタイムゾーンも更新します。

#!/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

答え3

現在のタイムゾーンがわからない場合は、最も簡単なソリューション

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

関連情報