Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Time Zone conflict betwen clients in a web application

by tokpela (Chaplain)
on Dec 15, 2009 at 10:12 UTC ( [id://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);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-19 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found