Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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

share|improve this answer
    
Thanks Iain :)...But when i gave JST as the timezone in the date -s command, the time decreased by 9 hours. From where does the system find out to decrease exactly 9 hours when JST is give as the input of date -s command? –  LinuxPenseur Dec 31 '10 at 9:16
    
Timezone information is under /usr/share/zoneinfo, at least for Fedora. –  mpez0 Dec 31 '10 at 19:32
    
I do not have the timezone package installed. Still when i simply execute the command date -s "12/30/2010 JST 14:19:47", the time is exactly the time of Japan, 9 hours behind UTC, although the timezone is not changing in the output. I want to know, how date decreases exactly 9 hours even though there is no timezone package installed. –  LinuxPenseur Jan 3 '11 at 3:50
    
@LinuxPenseur: See my edit for more information –  Iain Jan 3 '11 at 17:52

Just set your timezone properly and then you will be able to use the date command "naturally".

export TZ=JST
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.