Sep 23, 2023 4 min read

How To Set or Change Timezone on Debian 9

Set or Change Timezone on Debian 9 with our step-by-step tutorial. It refers to the geographical region where a computer system is located.

 Set or Change Timezone on Debian 9
Table of Contents

Introduction

Before we begin talking about how to set or change timezone on Debian 9, let's briefly understand – What is Timezone?

A timezone refers to the geographical region where a computer system is located. It helps to determine the local time of the system by considering the offset from Coordinated Universal Time (UTC).

Timezones play a crucial role in various operations, including scheduling tasks, timestamping files, and displaying accurate local time on the system. Understanding and correctly configuring timezones on Linux ensures accuracy in time-related operations and improves system performance.

In this tutorial, you will set or change timezone on Debian 9. We will also address a few FAQs on how to set or change timezone on Debian 9.

Advantages of Timezone

  1. Accurate time representation: Timezones allow precise representation of local time on computers, ensuring accurate scheduling, logging, and synchronization.
  2. Global coordination: Timezone management enables seamless collaboration and synchronization of events across different regions.
  3. Efficient task scheduling: With timezones, tasks can be scheduled and executed based on local time, ensuring smooth operation irrespective of geographical locations.
  4. Timestamp accuracy: Timezones aid in accurate recording of timestamps on files, emails, and other data, facilitating organization and tracking.
  5. Worldwide communication: Timezone support facilitates effective communication and real-time interactions across different time zones, promoting global connectivity and collaboration.

Prerequisites

To alter the system's timezone, the user you're logged in as must have sudo access.

Checking the Current Timezone

The timedatectl command in Debian and other recent Linux distributions allows you to view and change the current system's time and timezone.

timedatectl

The system's timezone is set to "America/Chicago," as shown in the output below:

Output

Local time: Mon 2022-05-23 16:46:45 CDT
  Universal time: Mon 2022-05-23 21:46:45 UTC
        RTC time: Mon 2022-05-23 21:46:45
       Time zone: America/Chicago (CDT, -0500)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

Symlinking /etc/localtime to a binary timezone identifier in the /usr/share/zoneinfo directory sets the system timezone. Another way to check the timezone is to use the ls command to see the path to which the symlink points:

ls -l /etc/localtime
Output

lrwxrwxrwx 1 root root 37 Jan 23 03:19 /etc/localtime -> ../usr/share/zoneinfo/America/Chicago

Changing Timezone in Debian

You must first determine the lengthy name of the timezone you want to use before altering it. The "Region/City" pattern is commonly used when naming timezones.

You can either list the files in the /usr/share/zoneinfo directory or use the timedatectl command to see all available time zones.

timedatectl list-timezones
Output

...
Europe/Lisbon
Europe/Ljubljana
Europe/London
Europe/Luxembourg
Europe/Madrid
Europe/Malta
...

Run the following command as sudo user once you've determined which time zone is correct for your location:

sudo timedatectl set-timezone your_time_zone

To set the system's timezone to Europe/Ljubljana, for example, type:

sudo timedatectl set-timezone Europe/Ljubljana

Use the timedatectl command to confirm the change:

timedatectl
Output

Local time: Mon 2022-05-23 22:51:27 CET
  Universal time: Mon 2022-05-23 21:51:27 UTC
        RTC time: Mon 2022-05-23 21:51:26
       Time zone: Europe/Ljubljana (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

If you're using an older version of Debian and don't have the timedatectl command, you can change your timezone by symlinking /etc/localtime to the timezone in the /usr/share/zoneinfo directory.

Delete or symlink the current /etc/localtime file:

sudo rm -f /etc/localtime

Create a symlink for the timezone you want to configure:

sudo ln -s /usr/share/zoneinfo/Europe/Ljubljana /etc/localtime

By listing the /etc/localtime file or using the date command, you may verify the change:

date
Mon May 23 22:55:04 CET 2022

FAQs to Set or Change Timezone on Debian 9

How do I list all available timezones on Debian 9? 

Use the command timedatectl list-timezones to get a list of all available timezones on Debian 9.

How can I set the timezone on Debian 9? 

To set the timezone on Debian 9, use the command timedatectl set-timezone <timezone>.

Can I change the timezone on Debian 9 without restarting? 

Yes, you can change the timezone without restarting by using the command systemctl restart systemd-timedated.

What should I do if the timezone change doesn't take effect immediately? 

Try executing timedatectl set-timezone <timezone> and then restarting the system with reboot command to ensure the changes take effect.

How do I change the timezone for a specific user on Debian 9? 

Each user can set their own timezone using the timedatectl set-timezone <timezone> command.

Can I manually edit the timezone configuration file on Debian 9? 

It is recommended to use the timedatectl command to change the timezone. Manual editing of timezone configuration files may lead to unexpected issues.

How can I confirm if the timezone has been successfully changed? 

After changing the timezone, use the command timedatectl show --property=Timezone to verify if the new timezone is correctly set.

Conclusion

You learned how to change the timezone of your Debian system in this tutorial.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.