| |||||||||||
Problem with localtime Posted by mescorpion (mescorpion), 14 June 2005 Hi,I am trying to find difference between 2 given dates... I have the date in the format as the "date" command output. Lets say: Tue Jun 14 00:15:35 PDT 2005 So i am trying to find the difference... the easier way i found was while taking the ouput of date command take the output of $ date +%s 1118733402 or else we can use time function also while executing the script.. So we will take the time in seconds while executing the date... so now... for finding the difference... we will find the difference between seconds... and convert it into HH:MM:SS. So i will subtract the seconds and pass it to localtime which give me the string in format.... lets assume difference... is always less than 24 hrs... in that case it has to return me the correct time after 1 Jan 1970 right .... mean to say if i pass 0 seconds to localtime it should return 1st Jan 1970 00:00:00. But localtime is showing something else... is that depends upon some other thing... is that logic correct... please answer.... Posted by admin (Graham Ellis), 14 June 2005 localtime returns a string containing the time and date if you run it in a scalar context, and a list of the various components of the time and date if you run it in a list context. Thus:Code:
gives you Tue Jun 14 09:01:51 2005 51 1 9 14 5 105 2 164 1 Thu Jan 1 01:00:00 1970 0 0 1 1 0 70 4 0 0 Posted by mescorpion (mescorpion), 14 June 2005 hithe thing is on my linux system here is what i have coded: $ cat ara.pl #!/usr/bin/perl $demo=localtime(0); print $demo; Here is the output: $ perl ara.pl Wed Dec 31 16:00:00 1969 Thats y i am got worried, is something wrong with my system.... Posted by admin (Graham Ellis), 14 June 2005 I think you're 8 hours behind GMT? West coast of the USA?You are using the LOCALtime function to get the time on your system ... where at 4p.m. on 31st December, it's midnight here in London. Note the gmtime function which returns information about normalised (GMT) times. Posted by mescorpion (mescorpion), 14 June 2005 hey its working fine with gmtime...thanks for that... i used gmtime its working fine... rather than using localtime its giving correct results.... $ cat ara.pl #!/usr/bin/perl $demo=localtime(0); print $demo; $demo1=gmtime(0); print "\n".$demo1; $ perl ara.pl Wed Dec 31 16:00:00 1969 Thu Jan 1 00:00:00 1970 Thank u very much This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |