Given a string that represents a date/time in ISO8601 format (e.g. 20100723T073000
), I need to ultimately parse this into a user-supplied format using a general strftime
format string. In order to do that, I need to convert the ISO8601 timestamp to a Unix timestamp. There are a huge amount of date/time manipulation modules for Perl and I'm a little overwhelmed. Any suggestions on how to do this?
views:
41answers:
1
+5
A:
The champion module for handling dates, times, durations, timezones and formats is DateTime. Once you've got your DateTime object, you can perform a huge number of operations on it, like adding/subtracting other DateTime objects or DateTime::Duration objects, or printing it out in another format.
use strict; use warnings;
use DateTime;
use DateTime::Format::ISO8601;
my $dt = DateTime::Format::ISO8601->parse_datetime('20100723T073000');
print $dt->strftime('%F %T');
prints: "2010-07-23 07:30:00"
Ether
2010-06-24 20:51:05