Mega Code Archive

 
Categories / Perl / Data Type
 

Converting Time

#!/usr/bin/perl ($thisMonth, $thisYear, $thisDay) = split(/:/,`date +%m:%Y:%d`); ($thisMonth, $thisDay, $thisYear ) = MMDDYYYY(); sub MMDDYYYY(){    my @timeList = localtime(time);    my $MM = sprintf("%02d",$timeList[4]+1);    my $YYYY = normalizeYear($timeList[5]);    my $DD = sprintf("%02d",$timeList[3]);    return ($MM,$DD,$YYYY); } sub normalizeYear {    local ($yearToNormalize) = @_;    if ($yearToNormalize < 90) {       sprintf "20%.2d",$yearToNormalize;    }elsif ($yearToNormalize < 100) {       sprintf "19%.2d",$yearToNormalize;    }else {       sprintf "%.4d",$yearToNormalize;    } } return 1;