Converting Time : date time « Data Type « Perl






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;

   
    
  








Related examples in the same category

1.To extract the current date by using time and localtime
2.Set the value of localtime to a scalar variable, you'll get a typical UNIX-style time
3.scalar(localtime(time()))
4.Splitting Time
5.Create new time based on the value from localtime
6.Print out the current time in standard time
7.Is leap year subroutine
8.Execute date command and get user input
9.Time of Day
10.Switch Time
11.Splitting Local Time
12.localtime converts a time into the local time.
13.gmtime function converts a time value into Greenwich Mean Time