Linux – Question on date and timezone in Linux

datelinuxtimezoneunix

I did the date command and it gave the following output

root@localhost:~$ date
Thu Dec 30 14:19:47 UTC 2010

Then i modified the date using date -s command whichn gave the following output

root@localhost:~$ date -s "12/30/2010 JST 14:19:47"
Thu Dec 30 05:19:47 UTC 2010

I noticed that the time changed to 9 hours behind UTC time to show exactly the JST time. But timezone as you can see is still showing UTC. Why is it showing the correct time and incorrect timezone?

Thanks

Best Answer

This is because your system is set to use UTC (or has no Time Zone set) and not JST. The date command will accept JST as an input modifier but then uses the system default to display it. If you want your system to want your system to display the time in JST format then you should set the timezone to JST

remove or rename /etc/localtime and then link the relevant file in /usr/share/zoneinfo to /etc/localtime

cd /etc
mv localtime localtime.orig
ln -s /usr/share/zoneinfo/Japan /etc/localtime

Edit

To answer your comment - The date command has to be able to understand time zone information provided as part of the date string parameter of -s and what to do with it. If you examine the source code you will find that all of the common time zone abbreviations, and their offsets from GMT are defined. This information is then used to set the time correctly. Depending on the version of core-utils you examine you'll find the information in lib/parse-datetime.c or lib/getdate.c