Is it possible to do timezone conversion for an 'arbitrary' date in the future using just Perl core modules?

Lets say I have the Day:month:year, hr:min in timezone X (assume its a fully qualified timezone like America/New_York) and I need to convert that to timezone Y (say Asia/Kolkata)

Some notes:

1) This is for OSX (Lion or above)

2) I know how to do it using DateTime and DateManip, but these are not core modules, and require a C compiler to be present to be installed. I am trying to distribute my program to 'non technical' users - they can do perl module installs with help, but fall apart when trying to get XCode, command line tools etc working. Some have tried to install DateTime but they got caught in errors/dependencies and gave up.

3) I tried using a combination of tzset; and ENV TZ - but that can't be used for arbitrary dates - only works with local time (Which means, I can convert 'now time' to any timezone)

有帮助吗?

解决方案

Use the POSIX core module. Example:

use POSIX;

$ENV{TZ} = 'Europe/Madrid';
$time_t = POSIX::mktime( 10, 30, 17, 4, 4, 113 );
print POSIX::ctime($time_t); #<-- prints: Sat May  4 17:30:10 2013

$ENV{TZ} = 'Europe/London';
print POSIX::ctime($time_t); #<-- prints: Sat May  4 16:30:10 2013
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top