programming-examples/perl/Datatype/Converting Time.pl

21 lines
630 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/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;