Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://812853]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2018-04-26 08:15 GMT
Find Nodes?
    Voting Booth?