Code would be nice but a point in the right direction is good as well.
CPAN? RegEx?
I've seen both ways
"yyyy-MM-dd'T'HH:mm:ssZ";
"yyyy-MM-ddTHH:mm:ssZ";
Ether is definitely on the right track with DateTime. Using DateTime, you can be sure that you have a time that actually exists, where something on Feb 29, 2000 might get by if you wrote the checks yourself.
Your format looks like an ISO8601 string. So, use DateTime::Format::ISO8601 to do your parsing.
use DateTime;
use DateTime::Format::ISO8601;
my $string = '2010-02-28T15:21:33Z';
my $dt = DateTime::Format::ISO8601->parse_datetime( $string );
die "Impossible time" unless $dt;
You could use other format modules, such as D::F::Strptime, but you will wind up recreating what ISO8601 formatter already does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With