如何在Perl中验证日期字符串?我想说明闰年和时区.有人可能会按以下格式输入日期:
11/17/2008 11/17/2008 3pm 11/17/2008 12:01am 11/17/2008 12:01am EST 11/17/2008 12:01am CST
解决方法
我用
DateTime::Format::DateManip这样的东西.使用你的约会….
use DateTime::Format::DateManip; my @dates = ( '11/17/2008','11/17/2008 3pm','11/17/2008 12:01am','11/17/2008 12:01am EST','11/17/2008 12:01am CST',); for my $date ( @dates ) { my $dt = DateTime::Format::DateManip->parse_datetime( $date ); die "Cannot parse date $date" unless defined $dt; say $dt; } # no dies.. produced the following.... # => 2008-11-17T00:00:00 # => 2008-11-17T15:00:00 # => 2008-11-17T00:01:00 # => 2008-11-17T05:01:00 # => 2008-11-17T06:01:00
NB.我在GMT这里!