1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
sub printDate
{ my ($day, $month, $year) = @_ ;
print(sprintf("%02s/%02s/%s\n", ($day, $month+1, $year+1900)));
}
# Aujourd'hui ...
my ($mday,$mon,$year) = (localtime(time))[3..5];
printDate($mday,$mon,$year);
# Le 1er du mois courant ...
my $first_M = timelocal(0, 0, 0, 1, $mon, $year);
printDate(1,$mon,$year);
# Le dernier du mois précédent ...
my $last_M_1 = $first_M - 2*60*60; # $first_M = 1er du mois à 0h00 => Au cas où changement d'horaire, soustraire 2h00 suffit
($mday,$mon,$year) = (localtime($last_M_1))[3..5];
printDate($mday,$mon,$year);
# Le 1er du mois précédent ...
#my $first_M_1 = timelocal(0, 0, 0, 1, $mon, $year);
printDate(1,$mon,$year); |
Partager