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

Re^4: Timezone antidote

by hatter (Pilgrim)
on Sep 01, 2005 at 12:00 UTC ( #488356=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Timezone antidote
in thread Timezone antidote

GMT is the storage solution, not the output format. Store all the times in UTC/GMT, and when you actually need to print them out, then use TZ-aware tools and use the localtime features. From one of my scripts, I have:

use POSIX qw(LC_TIME); $ENV{'TZ'} = "GMT-1"; $locale = "gb_UK"; POSIX::setlocale(LC_TIME,$locale); my $todaysdate = POSIX::strftime("%a %b %d %H:%M",localtime());
For the machines in the UK, that changes between -1 and -0 for summer and not, and the machines in germany, that changes between -2 and -1 for summer and winter, and locale is de_DE. Calling localtime() will then view the time as it should be in your locale.


the hatter


Comment on Re^4: Timezone antidote
Select or Download Code
Re^5: Timezone antidote
by Andre_br (Pilgrim) on Sep 06, 2005 at 17:11 UTC
    Hello hatter and everybody

    Thanks for the tips. Specially yours, hatter. But, tell me, any tip for mysql? My problem is the 'timestamp' fields, on wich rely my code and I´d have to convert them all to 'datetime' and make my code treat this offset.

    I tried setting the default of this 'timestamp' column to CURRENT_TIMESTAMP + interval 4 hour but this formula isn´t accepted by mysql as a default. I thought then about setting some kind of variable as now() + interval 4 hour but I think it won´t work either.

    Any ideas? My host said there´s no way to set a different time_zone through .my.cnf

    Thanks

    André

      DATE_ADD(NOW(),INTERVAL 4 hour) would be the option if you're setting itn in your INSERTs, DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 4 hour) may work in the column definition as the default value, if you've not tried that already.


      the hatter

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-07-31 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls