Changing default date and timezones

There are a few different ways to change the default date and timezone within CentOS operating system for web servers with only command line / SSH access. Below are separate methods outlined for CentOS 6 and CentOS 7. Three useful tutorial links for further reading can be found at:

Centmin Mod default method used to change the timezone involves basically one variable in and two lines of commands to run in SSH telnet session.

rm -f /etc/localtime
ln -s /usr/share/zoneinfo/$ZONEINFO /etc/localtime

The ZONEINFO variable defines the default timezone at Centmin Mod installation time, while the last 2 command lines remove existing localtime and symlinks to ZONEINFO defined preset value.

You can see the full list of possible values for ZONEINFO at /usr/share/zoneinfo. For example, top level

ls /usr/share/zoneinfo/
Africa      Australia  Cuba     Etc      GMT0       Iceland      Japan      MST      Poland      right      Universal  Zulu
America     Brazil     EET      Europe   GMT-0      Indian       Kwajalein  MST7MDT  Portugal    ROC        US
Antarctica  Canada     Egypt    Factory  GMT+0      Iran         Libya      Navajo   posix       ROK        UTC
Arctic      CET        Eire     GB       Greenwich  MET        NZ       posixrules  Singapore  WET
Asia        Chile      EST      GB-Eire  Hongkong   Israel       Mexico     NZ-CHAT  PRC         Turkey     W-SU
Atlantic    CST6CDT    EST5EDT  GMT      HST        Jamaica      Mideast    Pacific  PST8PDT     UCT

For Australia:

ls /usr/share/zoneinfo/Australia/
ACT       Brisbane     Canberra  Darwin  Hobart  Lindeman   Melbourne  NSW    Queensland  Sydney    Victoria  Yancowinna
Adelaide  Broken_Hill  Currie    Eucla   LHI     Lord_Howe  North      Perth  South       Tasmania  West

For America:

ls /usr/share/zoneinfo/America/
Adak            Blanc-Sablon   Cordoba       Fort_Wayne    Inuvik         Manaus       Montserrat      Porto_Velho    Shiprock       Vancouver
Anchorage       Boa_Vista      Costa_Rica    Glace_Bay     Iqaluit        Marigot      Nassau          Puerto_Rico    Sitka          Virgin
Anguilla        Bogota         Cuiaba        Godthab       Jamaica        Martinique   New_York        Rainy_River    St_Barthelemy  Whitehorse
Antigua         Boise          Curacao       Goose_Bay     Jujuy          Matamoros    Nipigon         Rankin_Inlet   St_Johns       Winnipeg
Araguaina       Buenos_Aires   Danmarkshavn  Grand_Turk    Juneau         Mazatlan     Nome            Recife         St_Kitts       Yakutat
Argentina       Cambridge_Bay  Dawson        Grenada       Kentucky       Mendoza      Noronha         Regina         St_Lucia       Yellowknife
Aruba           Campo_Grande   Dawson_Creek  Guadeloupe    Knox_IN        Menominee    North_Dakota    Resolute       St_Thomas
Asuncion        Cancun         Denver        Guatemala     Kralendijk     Merida       Ojinaga         Rio_Branco     St_Vincent
Atikokan        Caracas        Detroit       Guayaquil     La_Paz         Metlakatla   Panama          Rosario        Swift_Current
Atka            Catamarca      Dominica      Guyana        Lima           Mexico_City  Pangnirtung     Santa_Isabel   Tegucigalpa
Bahia           Cayenne        Edmonton      Halifax       Los_Angeles    Miquelon     Paramaribo      Santarem       Thule
Bahia_Banderas  Cayman         Eirunepe      Havana        Louisville     Moncton      Phoenix         Santiago       Thunder_Bay
Barbados        Chicago        El_Salvador   Hermosillo    Lower_Princes  Monterrey    Port-au-Prince  Santo_Domingo  Tijuana
Belem           Chihuahua      Ensenada      Indiana       Maceio         Montevideo   Porto_Acre      Sao_Paulo      Toronto
Belize          Coral_Harbour  Fortaleza     Indianapolis  Managua        Montreal     Port_of_Spain   Scoresbysund   Tortola

To view your current date, type 'date' command in SSH telnet:

Sun Feb 26 01:26:32 EST 2012

To change the timezone, you can either do it same way Centmin Mod default install does it, and remove the /etc/localtime file and symlink it to another ZONEINFO setting:

rm -f /etc/localtime
ln -s /usr/share/zoneinfo/$ZONEINFO /etc/localtime

Or for CentOS 7.x only you can use thetimedatectl command in SSH telnet. For example to change to Los Angeles timezone:

Find your Zone info code:

timedatectl list-timezones | grep 'America\/Los'

Then change it:

timedatectl set-timezone America/Los_Angeles

Verify settings:

ls -l /etc/localtime

Or for CentOS 6.x only you can use the tzselect command in SSH telnet. For example to change to Bahamas timezone:

You may need to remove the existing symlink before using tzselect

rm -f /etc/localtime
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 2
Please select a country.
 1) Anguilla                       28) Haiti
 2) Antigua & Barbuda              29) Honduras
 3) Argentina                      30) Jamaica
 4) Aruba                          31) Martinique
 5) Bahamas                        32) Mexico
 6) Barbados                       33) Montserrat
 7) Belize                         34) Nicaragua
 8) Bolivia                        35) Panama
 9) Bonaire Sint Eustatius & Saba  36) Paraguay
10) Brazil                         37) Peru
11) Canada                         38) Puerto Rico
12) Cayman Islands                 39) Sint Maarten
13) Chile                          40) St Barthelemy
14) Colombia                       41) St Kitts & Nevis
15) Costa Rica                     42) St Lucia
16) Cuba                           43) St Martin (French part)
17) Curacao                        44) St Pierre & Miquelon
18) Dominica                       45) St Vincent
19) Dominican Republic             46) Suriname
20) Ecuador                        47) Trinidad & Tobago
21) El Salvador                    48) Turks & Caicos Is
22) French Guiana                  49) United States
23) Greenland                      50) Uruguay
24) Grenada                        51) Venezuela
25) Guadeloupe                     52) Virgin Islands (UK)
26) Guatemala                      53) Virgin Islands (US)
27) Guyana
#? 5

The following information has been given:


Therefore TZ='America/Nassau' will be used.
Local time is now:      Sat Feb 25 10:28:19 EST 2012.
Universal Time is now:  Sat Feb 25 15:28:19 UTC 2012.
Is the above information OK?
1) Yes
2) No
#? y
Please enter 1 for Yes, or 2 for No.
#? 1

You can make this change permanent for yourself by appending the line
        TZ='America/Nassau'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts: