开发者

Matching a date in perl

I want to match a date in the format day/month/year. where day is two digits month is two digits a开发者_运维百科nd year is four digits. Also, I want to check see if it is a valid date, for example knows when is leap year, and know which month has 30days, 31days and 28, or 29 days for Februrary.


Take a look at something like Date::Manip; there's little sense in doing this yourself when things like this are available.

$date = ParseDate($mydate);
unless ($date) {
  # error
}
...


use the following code

use strict;
use warnings;
use Date::Manip;
my $start="2010:03:30:23:02:3";
my $split=":";
my($year,$month,$date,$hour,$min,$sec);

($year,$month,$date,$hour,$min,$sec)=split($split,$start);

my $result = ParseDate("$month/$date/$year");
if(!$result)
{
    print "Invalid Date\n";
    exit;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜