Linux – CentOS – Set Timezone

Background

Playing around with Linux, queried the system for the current time, and noticed it is a bit off.

 

OS

OS – Linux – CentOS

Our OS is CentOS/Version 8.

Command

hostnamectl

We can issue hostnamectl, to get the OS Name and Version.

Output

hostnamectl.image.01.20200607.0822PM

 

 

timedatectl

Outline

  1. timedatectl
    • timedatectl status
    • timedatectl list-timezones
    • timedatectl set-timezone
    • timedatectl show

status

Syntax

timedatectl status

Sample

timedatectl status

Output
Output – Textual

>timedatectl status
Local time: Sun 2020-06-07 19:24:29 PDT
Universal time: Mon 2020-06-08 02:24:29 UTC
RTC time: Mon 2020-06-08 02:24:29
Time zone: America/New_York (PDT, -0700)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Output – Image

timedatectl.status.01.20200607.0737PM

Explanation

  1. Time zone
    • Time zone is “America/New York ( PDT, -0700 )

 

List Timezones

Syntax

timedatectl  list-timezones

Sample

timedatectl  list-timezones | grep 'America'

Output
Output – Textual
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Inuvik
America/Iqaluit
America/Jamaica
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles
America/Lower_Princes
America/Maceio
America/Managua
America/Manaus
America/Marigot
America/Martinique
Output – Image

timedatectl.listTimeZones.01.20200607.0746PM

Explanation

  1. We listed timezones in the Americas

 

Set Timezone

Syntax

sudo timedatectl set-timezone [timezone]

Sample

sudo timedatectl set-timezone America/Los_Angeles

Output
Output – Textual
>sudo timedatectl set-timezone America/Los_Angeles
[sudo] password for dadeniji:

Output – Image

timedatectl.setTimeZone.01.20200607.0752PM

Explanation

  1. We successfully set our machine’s timezone to “America/Los_Angeles”

 

Show

Syntax

timedatectl show

Sample

timedatectl show

Output
Output – Textual
>timedatectl show
Timezone=America/Los_Angeles
LocalRTC=no
CanNTP=yes
NTP=yes
NTPSynchronized=yes
TimeUSec=Sun 2020-06-07 20:11:11 PDT
RTCTimeUSec=Sun 2020-06-07 20:11:11 PDT
>
Output – Image

timedatectl.show.01.20200607.0813PM

Explanation

  1. Timezone
    • Our Timezone has been set to “America/Los_Angeles

 

Configuration File

/etc/localtime

List File
Syntax

ls /etc/localtime

Sample

ls -la /etc/localtime
Output
Output – Textual

>ls -la /etc/localtime
lrwxrwxrwx. 1 root root 41 Jun  7 19:49 /etc/localtime -> ../usr/share/zoneinfo/America/Los_Angeles
Output – Image

etc.localtime.ls.01.20200607.0835PM

Explanation

  1. /etc/localtime
    • /etc/localtime is soft-linked to ../usr/share/zoneinfo/America/Los_Angeles

 

Summary

You very well may have to restart some of your applications to ensure that the timezone entry is reread.

References

  1. Quadranet
    • How to Change Timezone on CentOS Server
      Link
  2. The Geek Stuff ( RAMESH NATARAJAN )
    • How To: 2 Methods To Change TimeZone in Linux
      Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s