Skip to main content

修改系统时区

 

How To Set or Change Timezone on Ubuntu 20.04

https://linuxize.com/post/how-to-set-or-change-timezone-on-ubuntu-20-04/

 Using the correct timezone is essential for many systems related tasks and processes. For example, the cron daemon uses the system’s timezone for executing cron jobs, and the timestamps in the log files are based on the same system’s timezone.

On Ubuntu, the system’s timezone is set during the install, but it can be easily changed at a later time.

This article describes how to set or change the timezone on Ubuntu 20.04 using the command line, or through the GUI.

Prerequisites

Only the root or user with sudo privileges can set or change the system’s timezone.

Checking the Current Timezone

timedatectl is a command-line utility that allows you to view and change the system’s time and date. It is available on all modern systemd-based Linux systems, including Ubuntu 20.04.

To print the current system’s timezone invoke the timedatectl without any arguments:

timedatectl

The output below shows that the system’s timezone is set to “UTC”:

               Local time: Wed 2020-05-06 19:33:20 UTC
           Universal time: Wed 2020-05-06 19:33:20 UTC
                 RTC time: Wed 2020-05-06 19:33:22    
                Time zone: UTC (UTC, +0000)           
System clock synchronized: yes                         
              NTP service: active                      
          RTC in local TZ: no   

The system timezone is configured by symlinking /etc/localtime to a binary timezone identifier in the /usr/share/zoneinfo directory.
Another option to view the current system’s timezone is find the file to which the symlink points to:

ls -l /etc/localtime
lrwxrwxrwx 1 root root 27 Dec 10 12:59 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

The system’s timezone in also written to the /etc/timezone file:

cat /etc/timezone
UTC

Changing the Timezone Using the timedatectl Command

Before changing the timezone, you’ll need to find out the long name for the timezone you want to use. The timezones are using “Region/City” format.

To list all available time zones, you can either list the files in the /usr/share/zoneinfo directory or invoke the timedatectl command with the list-timezones option:

timedatectl list-timezones
...
America/Montevideo
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
...

Once you identify which time zone is accurate to your location, run the following command as sudo user:

sudo timedatectl set-timezone your_time_zone

For instance, to change the system’s timezone to America/New_York:

sudo timedatectl set-timezone America/New_York

Invoke the timedatectl command to verify the changes:

timedatectl
               Local time: Wed 2020-05-06 15:41:42 EDT  
           Universal time: Wed 2020-05-06 19:41:42 UTC  
                 RTC time: Wed 2020-05-06 19:41:48      
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes                         
              NTP service: active                      
          RTC in local TZ: no   

Changing the Timezone Using the GUI

If you are running Ubuntu Desktop, you can change the current system’s timezone through the GUI.

  1. Open the system settings window by clicking on the Settings icon, as shown in the image below:

    Ubuntu System Settings
  2. In the system settings window click on the Date & Time tab. If the Automatic Time Zone set to ON and you have an Internet connection and location service enabled, the time zone should be automatically set according to your location.

  3. To select the new timezone, you can either click on the map or search for a time zone through the search bar.

    Ubuntu Change Timezone

    Once done, click on × to close the window.

Conclusion

We’ve shown you how to change your Ubuntu system’s timezone.

Popular posts from this blog

LinuxONE Community Cloud

LinuxONE Community Cloud 注册网址 https://linuxone.cloud.marist.edu/#/login 优点: 不限流量 无需登记信用卡等支付信息 仅需一个Email地址即可注册 VPS硬件配置为 VCPUS:2 / RAM:4096MB / Root Disk:50GB 系统映像为 ubuntu22.04

github.com/Nyr/wireguard-install

继上一期介绍纯命令行安装OPENVPN服务器之后,又发现了同一家Nyr的纯命令行安装wg开源代码。 来源如下:https://github.com/Nyr/wireguard-install 也是2行代码,直接生成二维码可以供手机扫描使用。这样省去了下载配置文件的麻烦,非常省心。 首先下载安装脚本 wget https://git.io/wireguard -O wireguard-install.sh 更改文件为可执行属性 chmod +x wireguard-install.sh 然后执行 sudo ./wireguard-install.sh 回答一些参数设置的问题,就可以安装起来了...

wireguard easy server setup

  If you haven't installed Docker yet, install it by running: $ curl -sSL https://get.docker.com | sh $ sudo usermod -aG docker $( whoami ) $ exit Run WireGuard Easy  ––––––––––––– docker run -d \   --name=WG-SCX \   -e WG_HOST=🚨你的伺服器IP \   -e PASSWORD=🚨你的管理界面密碼 \   -e WG_DEFAULT_DNS=8.8.8.8,8.8.4.4 \   -v ~/.wg-easy:/etc/wireguard \   -p 51820:51820/udp \   -p 51821:51821/tcp \   --cap-add=NET_ADMIN \   --cap-add=SYS_MODULE \   --sysctl="net.ipv4.conf.all.src_valid_mark=1" \   --sysctl="net.ipv4.ip_forward=1" \   --restart unless-stopped \   weejewel/wg-easy ––––––––––––––––––––––––––––––   ➡️ GitHub Repo (wg-easy): https://github.com/WeeJeWel/wg-easy docker images docker ps -a docker stop id docker rm id to check ...