1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #!/usr/bin/perl
use strict;
use warnings;
use Time::Local 'timelocal_nocheck';
### Lecture paramètres
my $months = shift(@ARGV) or die("usage : $0 <+/-MONTH>\n");
### récupération date courante
my (undef, undef, undef, $day, $month, $year) = localtime();
### reconstruction date voulue (en ajoutant les mois passés en paramètre)
my $timestamp = timelocal_nocheck(0, 0, 0, $day, $month + $months, $year);
### on récupère les composants de la date voulue
(undef, undef, undef, $day, $month, $year) = localtime($timestamp);
$year += 1900; # l'année retournée par localtime est relative à l'année 1900
$month += 1; # le mois est dans l'intervalle 0..11. pour l'affichage, nous souhaitons 1..12
### on l'affiche au format souhaité
printf("%04d%02d%02d", ($year, $month, $day)); |
Partager