On 2013-04-18 18:48, Uri Guttman wrote:
On 04/18/2013 03:13 AM, Dr.Ruud wrote:
If your box already is in that timezone, you can use localtime().
perl -Mstrict -we'
my @dt = reverse +(localtime)[0..5];
$dt[0] += 1900; # year
$dt[1] += 1; # month
printf qq{%s-%02d-%02d %02d:%02d:%02d\n}, @dt;
'
2013-04-18 09:09:22
i would think you would know about POSIX::strftime. much cleaner and
more flexible than doing it all by hand. it is in core and the standard
way to print timestamps in almost any format.
There is nothing wrong with using localtime like in my example.
Coming from DateTime::TimeZone, it can be seen as the other end of the
scale, but it is no rocket science, and `perldoc -f localtime` tells you
all you need.
Of course POSIX::strftime is fine as well. I use it often like this:
perl -Mstrict -MPOSIX=strftime -wle '
print strftime q{%F %T %z}, localtime;
'
2013-04-18 20:36:16 +0200
With DateTime, you can for example do:
perl -Mstrict -MDateTime -wle '
print DateTime
-> now(time_zone => "Europe/Amsterdam")
-> strftime(q{%F %T %z});
'
2013-04-19 08:23:30 +0200
Also check out Time::Local::timelocal.
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/