• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

timezone

Set Timezone Permanently

March 18, 2021

It’s recommended to set the clock to UTC. In rare occasions, local time may be needed.

Here’s how to set your server’s timezone permanently.

Check the date first.

date

date

Backup localtime. Set it to US Eastern Time.

mv /etc/localtime /etc/localtime.backup
ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

mv /etc/localtime /etc/localtime.backup ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

Backup clock. Set it to US Eastern Time.

cp -p /etc/sysconfig/clock /etc/sysconfig/clock.backup 
> /etc/sysconfig/clock
echo ZONE=\"America/New_York\" > /etc/sysconfig/clock

cp -p /etc/sysconfig/clock /etc/sysconfig/clock.backup > /etc/sysconfig/clock echo ZONE=\"America/New_York\" > /etc/sysconfig/clock

Run the date again to validate.

date

date

Filed Under: Linux Tagged With: permanent, redhat, set, timezone

Timedatectl

June 24, 2020

Here’s another way of setting your server’s timezone. See all the options under North America.

timedatectl list-timezones | grep -i America

timedatectl list-timezones | grep -i America

Set timezone.

timedatectl set-timezone America/New_York

timedatectl set-timezone America/New_York

To check.

date

date

Restart cron if needed.

systemctl restart cron.service

systemctl restart cron.service

Filed Under: Linux Tagged With: set, timedatectl, timezone

Ubuntu Server Timezone

April 24, 2017

If you want to run a couple of cron jobs, you may need to check if your server is using your timezone. You can determine the server’s timezone by simply typing the system’s date command. You’ll see right away if your server is using the same timezone.

$ date
Sun Apr 23 21:21:24 PDT 2017

$ date Sun Apr 23 21:21:24 PDT 2017

If it isn’t, then you need to change it so it’s in sync with cron jobs. To change timezone, run dpkg-reconfigure tzdata. You’ll be asked to choose a region and the nearest city. In this example, I’m picking the Americas/Los Angeles combination. Choose your own region and city.

$ sudo dpkg-reconfigure tzdata
Current default time zone: 'America/Los_Angeles'
Local time is now:      Sun Apr 23 21:24:57 PDT 2017.
Universal Time is now:  Mon Apr 24 04:24:57 UTC 2017.

$ sudo dpkg-reconfigure tzdata Current default time zone: 'America/Los_Angeles' Local time is now: Sun Apr 23 21:24:57 PDT 2017. Universal Time is now: Mon Apr 24 04:24:57 UTC 2017.

You may need to restart cron so that the new timezone can take effect.

$ sudo service cron restart

$ sudo service cron restart

Filed Under: Linux Tagged With: date, timezone

  • Home
  • About
  • Archives

Copyright © 2023