Change timezone linux ubuntu

Setting timezone from terminal

«which will set to gmt» But is there a way to set time zone with just the offset ie.-1 or +5 etc? I need to do this as I’m writing an application to adjust timeoffset or report logs and the only info I have is the user IP. I can use a webapp to find the location of the IP, but then I need to set offset which would be easy IF I could just get the offset of the location, but if I need to find zone and city it would be a real pain. If anyone knows the answer to how to set system clock with +/-hour would be great.

Please help us to pick up the accepted answer. I think @Mitch’s answer is the best askubuntu.com/a/323163/22308

@NamGVU No, Mitch’s is not the best solution, it’s a «GUI in a terminal» answer. Even the OP said » this wont work as i need to altr timezone from a program without user input i need a command i can feed into terminal not gui solution», and that’s the same objective most would want when looking for a «terminal solution,» a script-friendly one. Collin Anderson’s is better if you know a city, or Ryan’s for plain GMT+-n

8 Answers 8

To change time zone from terminal, just press Ctrl + Alt + T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo dpkg-reconfigure tzdata 

Once open, just follow the screens to change the time zone.

this wont work as i need to altr timezone from a program without user input i need a command i can feed into terminal not gui solution thanks for reply

thx. this helps, byt i’m already changed manually etc/timezone =) like php.net/manual/en/timezones.php . absolutely identical .

Reconfiguring tzdata seems to adjust the hardware clock too so that the displayed time stays the same after the time zone switch. You might want that if your time was correct but time zone was wrong. However you definitely don’t want to touch your hardware clock while traveling. The timedatectl approach seems to change time zone only.

You can also use the new timedatectl to set the time in 14.04.

sudo timedatectl set-timezone America/New_York 

To see all available options, you can run ls -R —group-directories-first /usr/share/zoneinfo . (Be careful not to modify or erase any file here.) More info about posix and right prefixes is here.

I realize this thread is a bit dated, but I was looking for a better solution because I needed to automatically set the timezone in a VM after a user downloads it from our website and deploys it. Here’s what I ended up with:

echo "Setting TimeZone. " export tz=`wget -qO - http://geoip.ubuntu.com/lookup | sed -n -e 's/.*\(.*\).*/\1/p'` && timedatectl set-timezone $tz export tz=`timedatectl status| grep Timezone | awk ''` echo "TimeZone set to $tz" 

This will query geoip.ubuntu.com from the server once it is started on the new network (my script checks for connectivity first course) and then set the server’s timezone based on the response.

Читайте также:  Say cheese kali linux

The «wget -q0 -» tells wget to output only the results to stdout which is then piped to the $tz variable.

Источник

How to Set or Change Timezone in Ubuntu Linux [Beginner’s Tip]

When you install Ubuntu, it asks you to set timezone. If you chose a wrong timezone or if you have moved to some other part of the world, you can easily change it later.

How to change Timezone in Ubuntu and other Linux distributions

There are two ways to change the timezone in Ubuntu. You can use the graphical settings or use the timedatectl command in the terminal. You may also change the /etc/timezone file directly but I won’t advise that.

I’ll show you both graphical and terminal way in this beginner’s tutorial:

How to Change Time Zone in Ubuntu

Method 1: Change Ubuntu timezone via terminal

Ubuntu or any other distributions using systemd can use the timedatectl command to set timezone in Linux terminal.

You can check the current date and timezone setting using timedatectl command without any option:

[email protected]:~$ timedatectl Local time: Sat 2020-01-18 17:39:52 IST Universal time: Sat 2020-01-18 12:09:52 UTC RTC time: Sat 2020-01-18 12:09:52 Time zone: Asia/Kolkata (IST, +0530) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no

As you can see in the output above, my system uses Asia/Kolkata. It also tells me that it is 5:30 hours ahead of GMT.

To set a timezone in Linux, you need to know the exact timezone. You must use the correct format of the timezone (which is Continent/City).

To get the timezone list, use the list-timezones option of timedatectl command:

timedatectl list-timezones

It will show you a huge list of the available time zones.

Timezones In Ubuntu

You can use the up and down arrow or PgUp and PgDown key to move between the pages.

You may also grep the output and search for your timezone. For example, if you are looking for time zones in Europe, you may use:

timedatectl list-timezones | grep -i europe

Let’s say you want to set the timezone to Paris. The timezone value to be used here is Europe/Paris:

timedatectl set-timezone Europe/Paris

It won’t show any success message but the timezone is changed instantly. You don’t need to restart or log out.

Keep in mind that though you don’t need to become root user and use sudo with the command but your account still need to have admin rights in order to change the timezone.

You can verify the changed time and timezone by using the date command:

[email protected]:~$ date Sat Jan 18 13:56:26 CET 2020

Method 2: Change Ubuntu timezone via GUI

Press the super key (Windows key) and search for Settings:

Applications Menu Settings

Scroll down a little and look for Details in the left sidebar:

Settings Detail Ubuntu

In Details, you’ll fine Date & Time in the left sidebar. Here, you should turn off Automatic Time Zone option (if it is enabled) and then click on the Time Zone:

Читайте также:  Шрифты по умолчанию linux

Change Timezone In Ubuntu

When you click the Time Zone, it will open an interactive map and you can click on the geographical location of your choice or type the city name. Once you have selected the correct timezone, close the window.

Set Timezone In Ubuntu

You don’t have to do anything other than closing this map after selecting the new timezone. No need to logout or shutdown Ubuntu.

I hope this quick tutorial helped you to change timezone in Ubuntu and other Linux distributions. If you have questions or suggestions, please let me know.

Источник

How do I change my timezone to UTC/GMT?

Any idea how I change from IST to GMT?

To switch to UTC, simply execute sudo dpkg-reconfigure tzdata , scroll to the bottom of the Continents list and select Etc or None of the above ; in the second list, select UTC . If you prefer GMT instead of UTC, it’s just above UTC in that list. 🙂

After I did what you wrote above, and changed the time zone, my server is still having the same wrong time, do I need to restart the system, or what?

From the command line in Ubuntu, the following link provides the trivial 1-line command: askubuntu.com/a/524362/182454

Simplicity! (KISS) Love it, Thanks! On a minimal Server install the other time Zones are not available, just UTC, so installing sudo apt install tzdata is a MUST!

sudo timedatectl set-timezone UTC 

Will change your timezone to UTC system wide.

You can do timedatectl list-timezones to see all the available timezones.

Zones like Etc/GMT+6 are intentionally reversed for backwards compatibility with POSIX standards. See the comments in this file.

You should almost never need to use these zones. Instead you should be using a fully named time zone like America/New_York or Europe/London or whatever is appropriate for your location. Refer to the list here.

In the old Un*x style (SunOS, HPUX. ), you can do:

ln -fs /usr/share/zoneinfo/UTC /etc/localtime 

Check the contents of /usr/share/zoneinfo to get the timezone you want/need.

For instance, Irish Summer Time (IST) can be defined as

-rw-r--r-- 1 root root 3661 Mar 13 22:18 /usr/share/zoneinfo/posix/Eire 
lrwxrwxrwx 1 root root 13 Mar 13 22:18 /usr/share/zoneinfo/Europe/Dublin -> ../posix/Eire 

However, the most important is to use a proper clock reference and a ntp daemon (openntpd for instance), as timezone is only used for displaying/converting the time to strings, not to store it (whatever the timezone, difference to 01/01/1970 is everywhere the same on Earth).

I can use this to change UTC to Asia/Kolkatta with.. sudo rm /etc/localtime (i had already this file so couldn’t create symlink with next command, so i deleted it first), sudo ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime . I think this seems to be a general solution.

Updated for 14.04 to present

View Time and Date Status:

$ timedatectl status Local time: Sun 2018-07-29 15:26:03 BST Universal time: Sun 2018-07-29 14:26:03 UTC RTC time: Sun 2018-07-29 14:26:03 Time zone: Europe/London (BST, +0100) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no 

View List of Timezones:
Listed Timezones (425)

$ timedatectl list-timezones Africa/Abidjan Africa/Accra Africa/Addis_Ababa . Pacific/Tongatapu Pacific/Wake Pacific/Wallis UTC 

Set Timezone to UTC:

$ timedatectl set-timezone UTC 

View Time and Date Status:

$ timedatectl status Local time: Sun 2018-07-29 14:46:27 UTC Universal time: Sun 2018-07-29 14:46:27 UTC RTC time: Sun 2018-07-29 14:46:27 Time zone: UTC (UTC, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no* 

Источник

Читайте также:  Password for users linux

How to Set or Change Timezone on Ubuntu 22.04

An area of the planet where the same standard time is observed is known as a Timezone. Every time zone has an identity that serves as a description, and it typically follows the format of region/city (Asia/Amman). The built-in “Date & Time” setting in Ubuntu 22.04 allows us to alter and configure the Timezone.

We will elaborate on the method to set Timezone on Ubuntu 22.04 in this article:

Method 1: Change Timezone on Ubuntu 22.04 using Terminal

On Ubuntu 22.04, to set the Timezone using the terminal, follow the steps listed below.

Step 1: Check current Timezone

First, open the terminal using “CTRL+ALT+T” and execute the below-given command to check the current Timezone:

The alternative method to check the Timezone is by using the “cat” command along with “/etc/timezone” path:

Step 2: Check list of Available Timezone

In the next step, get the list of Available Timezone on Ubuntu 22.04. The list contains regions along with city names. Then, select the required Timezone from the given list:

$ timedatectl list-timezones

Step 3: Set new Timezone

Set the region and Timezone according to your preferences. As “Africa/Cairo” Timezone is configured on our Ubuntu 22.04:

$ sudo timedatectl set-timezone Africa/Cairo

Move toward the Timezone confirmation.

Step 5: Confirm Timezone settings

Confirm the Timezone changes by executing the below-given command:

The given output indicates that we have successfully set our Timezone as “Africa/Cairo”:

Let’s check out the GUI method for setting Timezone.

Method 2: Change Timezone on Ubuntu 22.04 using GUI

To change the Timezone of the Ubuntu system using GUI, follow the provided steps carefully.

Step 1: Open Settings

First search “Settings” in the “Activities” menu and open it:

Step 2: Set Timezone

Select the “Date & Time” category of the system “Settings” and click on the highlighted “Time Zone” option:

Search for the desired Timezone in the search bar and select it from displayed options:

As you can see, we have successfully set new Timezone on Ubuntu 22.04:

We have effectively explained the methods to change or set the Timezone on Ubuntu 22.04.

Conclusion

To change the Ubuntu 22.04 Timezone, you can use Ubuntu’s terminal or GUI. In the first approach, check the available time zone. Then, use the command “$ sudo timedatectl set-timezone Region/City>” to define the desired Timezone. In the second approach, open the System “Settings”, select the “Date & Time” category, and change the new Timezone. We have demonstrated the methods to set or change the Timezone using the terminal and GUI on Ubuntu 22.04.

TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY

Источник

Оцените статью
Adblock
detector