Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Date and Time

by SuperCruncher (Pilgrim)
on Dec 03, 2002 at 00:19 UTC ( [id://217089]=note: print w/replies, xml ) Need Help??


in reply to Date and Time

I hasten to point out that just because your server is not in your timezone, it does not mean that it "cannot be relied upon to be accurate". But I know what you mean :-)

All you need to do is find out how many hours you are behind GMT, and substract that from localtime. Try this (untested):

my $time = localtime; my $hours_behind_gmt = 4; # localtime is in seconds, hence we need to get hours --> seconds my $time_in_my_timezone = localtime - ($hours_behind_gmt * 60 * 60); print scalar localtime($time_in_my_timezone);
Beware of the main caveat of dealing with different timezones: Daylight Savings Time. If your server is based in England, during the summer it will not use GMT--it will use BST (British Summer Time) instead. So beware.

For doing fancy operations with dates, you might like to use the Date::Calc module on CPAN. Finally, in future, please do a bit of research yourself. This is quite a basic question and the answer could probably be found with a bit of hacking and Google-ing. If you have done research, give us the code you've already got (even if you think it's bad). People are more inclined to help if you seem to be making a real effort yourself.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://217089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-24 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found