How to Set the Time Zone on Ubuntu 18.04 Server
To change the system time zone on Ubuntu 18.04 Server, first check the name with timedatectl list-timezones and then set it as shown in sudo timedatectl set-timezone Asia/Seoul. tzselect is a tool to find the time zone name, and running it alone does not change the system-wide settings.
Difference Between Time Zone and System Time
A time zone is a rule applied to display the same moment as a local date and time. For example, Asia/Seoul is the time zone name for Seoul and is 9 hours ahead of UTC (Coordinated Universal Time). Changing the time zone generally changes the display rule but does not synchronize the clock with an internet time server.
If you have scheduled tasks or log analysis that operate based on the local time on the server, check the impact of the change first. Some programs use their own time zone settings or environment variables, so they may appear different from the system settings. General security support for Ubuntu 18.04 has ended, so check the applicable scope in Ubuntu Security Maintenance Schedule and plan to migrate to a supported version.
Check the current time zone
Use the following command to check the system time and time zone settings. Record the name shown in Time zone before making changes so you can revert later.
timedatectl status
date
date -u
timedatectl status shows the system's local time, UTC, and time zone. date shows the local time applicable to the current environment, and date -u shows UTC. If the TZ environment variable is set in the current shell, date output may differ from the system's default time zone.
Change the system time zone using timedatectl
First, check the available time zone names. The list may vary depending on the installed time zone data.
timedatectl list-timezones | grep -F 'Asia/Seoul'
If Asia/Seoul is in the list, set the system time zone with the following command. Administrator privileges are required. If you are in a different region, replace it with the name found in the list.
sudo timedatectl set-timezone Asia/Seoul
timedatectl status
If the command is successful, the selected name will appear in Time zone. If an error occurs, check the case of the name, the available list, and administrator privileges. This command may not be usable if the system does not use systemd or if changes are restricted in a container.
To revert to the original time zone, use the name recorded before the change as an argument to the same command. For example, use the following command only when the previous value was Etc/UTC.
sudo timedatectl set-timezone Etc/UTC
timedatectl status
This command changes the time zone setting of /etc/localtime. If the hardware real-time clock (RTC) is set to local time, it may also affect the RTC. For more details, refer to Ubuntu 18.04 timedatectl manual.
Using tzdata and tzselect
You can also set the system time zone using an interactive menu with the following command. In the region list, select Asia, and in the city list, select Seoul. The numbers in the menu may vary depending on the environment, so check the items displayed on the screen.
sudo dpkg-reconfigure tzdata
After completion, check the system time zone again with timedatectl status. On the other hand, tzselect only prints the name of the selected time zone and does not change the time zone for the entire system. You can use the name obtained by selecting the region and city with timedatectl set-timezone.
tzselect
To execute a specific command in a different time zone, you can specify TZ for that command. The following example applies only to that single execution of date and does not change the system settings.
TZ=Asia/Seoul date
export TZ=Asia/Seoul affects the current shell and the programs started from that shell but does not change the system-wide settings. You can unset this variable in the current shell with unset TZ. For more details, refer to the Ubuntu tzselect manual.
Screen settings and post-change check
If a graphical desktop is installed, you can also select the time zone in the settings under Date & Time. If automatic time zone setting is enabled, manual selection may be restricted. The menu location varies depending on the desktop environment, and a typical Server installation may not have a graphical interface.
After the change, check timedatectl status and review the logs and scheduled tasks of affected services. If the time zone is correct but the actual time is incorrect, you need to separately check the time synchronization service and network connection. If only a specific application shows a different time, also check the TZ of that process and the application settings.




