How can I get UTC equivalents of Today_and_Now() and Today() call results? Can I convert them back to local time?
+1
A:
Have a look at "Programmatic Time Usage With Perl". This will explain you the brief summary of tips for using time functions in Perl.
Other then this you can also have a look at some perl modules i.e. Time::UTC::Now and DateTime::TimeZone
Space
2010-04-23 12:11:25
+6
A:
If you are using Today_and_Now() I assume that you're using Date::Calc. So, if you read the docs you will find that you can pass a parameter to both of those that indicates that gmtime() should be used as input rather than localtime(). Simply pass any true value to the these functions.
my ($year,$month,$day) = Today(1);
my ($year,$month, $day, $hours, $mins, $secs) = Today_and_Now(1);
Nic Gibson
2010-04-23 12:30:20
Why didn't you link directly to Date::Calc http://search.cpan.org/perldoc/Date::Calc or http://search.cpan.org/perldoc?Date::Calc ?
Brad Gilbert
2010-04-23 15:38:03
Because I wanted to point at the module not the docs?
Nic Gibson
2010-04-23 15:50:37
+2
A:
I've turned into more of a fan of DateTime each time I use it.
my $local_tz = DateTime::TimeZone->new( name=> 'local' );
my $now = DateTime->now( time_zone => $local_tz );
$now->set_time_zone('UTC');
say $now->hour(); ### UTC
$now->set_time_zone($local_tz);
say $now->hour(); ### Back to local time
Oesor
2010-04-24 04:05:06