When I manage server, there are many times the server have no right timezone as I want or customers want to change timezone of their server. 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.
Here I only show you a simplest way to change timezone by tzselect
First you may need to remove the existing symlink before using tzselect
rm -f /etc/localtime
Then use tzselect to choose your timezone step by steps
tzselect 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: Bahamas 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: America/Nassau
Now let ‘s restart your server to make sure everything work well.
As a bonus, here I will show you what timezone are supported on your server.
This command will list all countries
ls /usr/share/zoneinfo/
Let ‘s say you are in Australia then use this to list all supported timezone area in Australia
ls /usr/share/zoneinfo/Australia/
In manual way you can make a shellscript like this:
ZONEINFO=Australia/Brisbane rm -f /etc/localtime ln -s /usr/share/zoneinfo/$ZONEINFO /etc/localtime
and just run it to change to your timezone.
Happy coding