Display Date and Time in Linux
1
|
# date
|
and its output
1
|
Sat Mar 15 03:14:29 PDT 2014
|
Change Timezone in Linux
Fist, we are going to get a list of timezone that came with Linux.
1
|
# cd /usr/share/zoneinfo/ # ls
|
1
2
3
4
5
6
7
8
9
10
|
Africa Canada GB Indian Mexico ROK iso3166.tab
America Chile GB–Eire Iran NZ Singapore posix
Antarctica Cuba GMT Israel NZ–CHAT Turkey posixrules
Arctic EET GMT+0 Jamaica Navajo UCT right
Asia EST GMT–0 Japan PRC US zone.tab
Atlantic EST5EDT GMT0 Kwajalein PST8PDT UTC
Australia Egypt Greenwich Libya Pacific Universal
Brazil Eire HST MET Poland W–SU
CET Etc Hongkong MST Portugal WET
CST6CDT Europe Iceland MST7MDT ROC Zulu
|
There are countries, or continent with different timezone, for example when you list all file and directories in zoneinfo directory as I did above, there are timezone for countries with only one timezone, and directories for countries and continent with several timezones. For example my timezone is America Pacific, I will need to go to America directory to get my timezone.
1
2
|
# cd /usr/share/zoneinfo/Asia/
# ls
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
Aden Chungking Kabul Novokuznetsk Tashkent
Almaty Colombo Kamchatka Novosibirsk Tbilisi Amman Dacca Karachi Omsk Tehran Anadyr Damascus Kashgar Oral Tel_Aviv Aqtau Dhaka Kathmandu Phnom_Penh Thimbu Aqtobe Dili Katmandu Pontianak Thimphu Ashgabat Dubai Khandyga Pyongyang Tokyo Ashkhabad Dushanbe Kolkata Qatar Ujung_Pandang Baghdad Gaza Krasnoyarsk Qyzylorda Ulaanbaatar Bahrain Harbin Kuala_Lumpur Rangoon Ulan_Bator Baku Hebron Kuching Riyadh Urumqi Bangkok Ho_Chi_Minh Kuwait Saigon Ust-Nera Beirut Hong_Kong Macao Sakhalin Vientiane Bishkek Hovd Macau Samarkand Vladivostok Brunei Irkutsk Magadan Seoul Yakutsk Calcutta Istanbul Makassar Shanghai Yekaterinburg Chita Jakarta Manila Singapore Yerevan Choibalsan Jayapura Muscat Srednekolymsk Chongqing Jerusalem Nicosia Taipei |
I will use Toronto for Pacific time, so I will need to copy/set Toronto file as my localtime on my server (this will work with any linux system I believe).
1
|
# cp /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
|
Change Date and Time in Linux
Now your Linux system should have the timezone that you want. If the date or time is not correct, you can set date and time with date command.
1
|
# date MMDDhhmmYYYY
|
- MM: two digit month number
- DD: two digit date
- hh: two digit hour (24 hour system)
- mm: two digit minute
- YYYY: four digit of year
You can also sync your system time and date with ntp (Network Time Protocol) over a network or internet. Normally ntp should be installed to your Linux system as default, in case your system does not have ntp, you can easily install ntp package with a simple command.
To install ntp on Ubuntu, Linux or debian based distribitions
1
2
|
# apt-get update
# apt-get install ntp
|
To install ntp on Fedora, Centos or redhat based distribitions
1
|
# yum install ntp
|
After you set your timezone correcly, you should be able to synce your date and time with ntp command
1
|
# ntpdate pool.ntp.org
|
Note: if you have a VPS (virtual private server) and not a real dedicated server, you will properly won’t be able to adjust time on your VPS. When you are on VPS, you do not have the right to modify or update time and date, only the VPS owner or provider have the rights to adjust time and date on that VPS node.