Change Your Timezone In Linux

Today’s article is an easy one about how you can change your timezone which isn’t something you’ll likely need to do all that often. It’s not all that complicated, though it can look like it is. It can be a bit tedious, but that’s just at first blush. I’ll show you how to make it a bit easier.

NOTE: This is actually a duplicate. I wrote it some time ago and realized it was a duplicate, or reasonably close to another article. I decided to save it and publish a duplicate article when an ’emergency’ came up. Well, we have an ’emergency’. I had too many adult beverages before it was time to write a new article. So, you get this one.

Now, the title is obviously not correct. You’re not going to change your timezone, you’re going to change the timezone settings your computer is using. Alas, headlines aren’t to be all that long and are allowed to make some assumptions. If you want to change your timezone, you’ll have to move.

This article is only useful to you if you use systemd.

My regular readers may have noticed a giant outage. Linux-Tips.us was unreachable for a good part of the 6th. My initial assumptions were that we’d been hacked, that is that WordPress had become compromised. That’s a reasonable assumption.

It turns out that we’d been moved to a new data center. We’re now located in New York. I use a CDN that relies on an IP address. There are a bunch of DNS records behind the scenes. Those records had to be updated. That wasn’t a major task, but troubleshooting the problem was the challenge.

Everything turned out okay and I won’t even miss a scheduled publication. Of course, I’m writing this at 04:45, but you will have your article today. So far, I haven’t missed a publication date. I’m quite amazed by this.

Speaking of today’s article, we’re going to be learning how to change your timezone. We’ll be doing this in the terminal and the tool we’ll be using is known as timedatectl. If your distro uses systemd, you have this installed. When you check the man page (with man timedatectl) you’ll see that timedatectl defines itself as:

timedatectl – Control the system time and date

As you can see, this is probably the right tool for the job – assuming the job is changing your timezone. Seeing as that’s what the title says we’ll be doing, we might as well do that.

Change Your Timezone:

As mentioned in the introduction portion of this article, you’ll be doing the work in the terminal. It’s often easy to open a terminal with a keyboard shortcut. Frequently, you can open your default terminal by just pressing CTRL + ALT + T. Otherwise, look in your application menu. That’d be a good spot to look for a way to open your terminal.

With your terminal open,  you can enter the following command to see what you have for your current timezone settings:

Before you can change your timezone you have to know what time zones are available. There are a whole lot of them, meaning you can be scrolling for quite a while. Go ahead and enter this command:

(You can press CTRL + C to get out of that.)

So, what we’re going to do is narrow down the results shown to you. You’ll need to know the region you’re in, such as Europe, Africa, America, etc for this next part and we’re going to use a pipe and grep (which we’ve used in the past). For me, I’d want to set my timezone to New York in America and my command would look like:

You’ll note that this is case-sensitive. Listed in the output would be the text I’m after, the text needed for the command that lets you change your timezone. It looks like this:

With that information available, I can now complete the command to change my timezone to that of New York. That command is easy enough. It just looks like:

Or, when using my location as the example, the command looks like this:

It’s not too daunting a task to change your timezone. If you entered the wrong timezone during installation, you can trivially change it to the correct timezone.

I should mention that your computer will use NTP to keep your system’s clock set. This is also stored in your system’s hardware. The CMOS battery keeps that and other settings stored while the power is disconnected. This battery can go bad.

If that battery does go bad, you may find yourself setting the date and time of your system every time you start your computer. NTP should then kick in and keep your system’s time updated. For reasons deeper than this blog will go, your system depends on time (specifically Unix Time) in all sorts of applications.

Closure:

Well, there was some drama. The site was down for an extended period and this article wasn’t written until the wee hours of the morning. However… However, I didn’t miss a publication date. Also, I just realized I haven’t done a meta article in a while.

With some great help from the hosting company upstream, everything was resolved and you got an article about how to change your timezone in Linux. All’s well that ends well.

While there are backups, my heart sank when I thought that the site had been hacked. Cleaning that mess would have been tedious. Fortunately, that wasn’t required. No data was lost and we can move on knowing that it’s just a f