How can I change the timezone of a datetime value in Perl?

Anders picture Anders · Feb 1, 2010 · Viewed 13k times · Source

Using this function:

perl -e 'use Time::Local; print timelocal("00","00","00","01","01","2000"),"\n";'

It will return an epochtime - but only in GMT - if i want the result in GMT+1 (which is the systems localtime(TZ)), what do i need to change?

Thanks in advance,

Anders

Answer

jacktrade picture jacktrade · Nov 27, 2012
use DateTime;
my $dt   = DateTime->now;
$dt->set_time_zone( 'Europe/Madrid' );