Reputation: 519
I have a list of date-times in this format:
05/Jan/12 8:00 AM
The day is always two digits, but the hour can be either one or two digits.
I'd like to convert that to iCal format:
20120105T080000Z
Is there a module that does this?
Upvotes: 1
Views: 1601
Reputation: 7526
The Time::Piece core module would suffice:
#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
my $str = q(05/Jan/12 8:00 AM);
my $t = Time::Piece->strptime($str,"%d/%b/%y %I:%M %p");
print $t->datetime, "\n";
This assumes your localtime and would include dashes in the output:
2012-01-05T08:00:00
Upvotes: 4
Reputation: 2857
Should be able to do it using a combination of DateTime::Format::Strptime and DateTime::Format::ICal.
Also, your output appears to be in UTC/GMT (indicated by the trailing 'Z'), but your input doesn't specify a timezone. So as part of your solution you will need to specify what time zone the input times should be interpreted in.
See also http://datetime.perl.org/wiki/datetime/page/Modules
Upvotes: 2