Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Time Zone conflict betwen clients in a web application

by tokpela (Chaplain)
on Dec 15, 2009 at 10:12 UTC ( #812853=note: print w/ replies, xml ) Need Help??


in reply to Time Zone conflict betwen clients in a web application

You should be storing UTC time (also known as GMT) so that all of your timeframes are common across all timezones for consistency. Then, when you need to show the users their time - you can convert from GMT to localtime.

You can get the gmtime in seconds by using the Time::Local module. Here is a snippet that you can use to show how to do the time conversions:

use strict; use warnings; use Time::Local; my $time = time(); my $timegm = timegm(gmtime($time)); my $gmt = gmtime($time); my $timelocal = timelocal(localtime($time)); my $lmt = localtime($time); print "TIME: [$time]\n"; print "GMT: [$timegm]\n"; print "GMT AS TEXT: [$gmt]\n"; print "LOCALTIME: [$timelocal]\n"; print "LOCALTIME AS TEXT: [$lmt]\n";

To get the localtime of GMT use the seconds value of the gmtime in localtime

my $timelocal = timelocal(gmtime($timegm)); my $lmt = localtime($timegm);


Comment on Re: Time Zone conflict betwen clients in a web application
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2014-07-25 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls