Perl's Date::Manip - how to convert a given date into another timezone -
consider following code snippet takes user input (a date) , format using unixdate date::manip
#!/usr/bin/perl use date::manip; $input = join(" ", @argv); $date = unixdate($input, "%y-%m-%d %t"); print $date;
this done allow users enter friendly dates such "yesterday" or "1 week ago".
i use $date different timezone (it used extract sql data). how done? did not find construct of unixdate allow put timezone, , not know either how reformat user input (concatenating name of timezone doesn't help).
example
the user somewhere in central europe (timezone: cet) , enters "today @ 1pm". execution of code above follows:
$ ./test.pl today @ 1pm 2011-03-03 13:00:00
this expected result no timezone change in effect. use $date timezone, e.g. pacific standard (timezone: pst). in case output should be:
$ ./test.pl today @ 1pm 2011-03-03 04:00:00
try date_convtz()
function:
$date = unixdate( date_convtz( $input, 'cet', 'pst' ), "%y-%m-%d %t");
from manual date::manip::dm6
Comments
Post a Comment