Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Finding a remote time

by jaa (Friar)
on Jul 17, 2006 at 20:37 UTC ( [id://561848]=note: print w/replies, xml ) Need Help??


in reply to Finding a remote time

As a general rule, when having to deal with datetimes and timezones, NEVER store a localtime. If you are going to have users / processing in multiple timezones, the sanest way to deal with everything is to store it ALL in UTC / GMT from the outset.

Storing UTC makes it trivial to display correct localised date-times in Perl / various web and other front ends / languages etc using standard libraries, and without adding the overhead of your own complex date-math for all accesses to the data.

As an aside, MySQL <= 4.1 is a PITA for saving UTC - all the time functions are localtime, and affected by the TZ of your mysql daemon.

Use this expression for a UTC now() in MySQL:

update mytable set right_now=DATE_ADD('1970-01-01', INTERVAL UNIX_TIMESTAMP() SECON +D)
To get correct localtimes in Perl / etc, just make sure that you set the TZ of the process handling the request, and the localtime functions will do the hard work for you.

Regards,

Jeff

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-29 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found