开发者

Matching a date in perl

开发者 https://www.devze.com 2022-12-25 19:55 出处:网络
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 kn

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

精彩评论

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