Question by Munir: How to get local time using PERL while the server I am using is in a different time zone?
For example, my local time is 9 am August 17th. But the server is in 9pm August 16th time zone. How do I write PERL code to get my local time?
Answer to Martin:
Sorry for lack of info. I am quite new to PERL.
The cgi I am using is stored in a server in USA. (I live in Japan). It uses the PERL engine from
/usr/bin/perl of the server in USA to run the cgi script. I used the following code to get time:
($ sec,$ min,$ hour,$ mday,$ mon,$ year,$ wday,$ yday,$ isdst) = localtime(time);
Obviously it is showing the server’s local time. But I need to modify the code to get Japan’s local time.
Please let me know if you need further information. Thank you.
Thanks a lot for the detailed info. However, I have 2 problems.
1. How to pass the value created by javasript to the perl variable $ zone. PERL should execute before JS executes.
2. Getting the following error:
Can’t locate DateTime.pm in @INC (@INC contains: /usr/lib/perl5/5.8.7/i386-freebsd /usr/lib/perl5/5.8.7 /usr/lib/perl5/site_perl/5.8.7/i386-freebsd /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl .) at /test.cgi line 35.
BEGIN failed–compilation aborted at /test.cgi
Answer by martinthurn
We need more info to answer your question. Is your program running on the server? Or on your local machine? Are you getting the date from the server? Or trying to send a date to the server? Basically, what does the server have to do with the local time in the first place?
Know better? Leave your own answer in the comments!