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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/perl
use strict;
#package mon_package; # Enlever le commentaire pour déclarer le package
my @WEEK_DAYS = ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
my @MONTHS = ('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
my $time = time; #optionel #A supprimer pour faire un package
my $sql_date = conv_date($time, '%sql'); #A supprimer pour faire un package
my $date_normale = conv_date($time, '%d %B %Y'); #A supprimer pour faire un package
my $heure = conv_date($time, '%X'); #A supprimer pour faire un package
sub conv_date {
my($time, $format) = @_;
if (! $time) { $time = time; }
if (! $format) { $format = '%D' }
my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
my $full_en_text_date = localtime($time);
$mon++;
my $yearl = $year + 1900;
if ($year > 99) { $year -= 100; }
my $short_mon = substr($MONTHS[$mon - 1], 0, 3);
my $short_wday = substr($WEEK_DAYS[$wday], 0, 3);
my $mdayl = sprintf('%02d', $mday);
my $monl = sprintf('%02d', $mon);
$sec = sprintf('%02d', $sec);
$min = sprintf('%02d', $min);
$hour = sprintf('%02d', $hour);
$year = sprintf('%02d', $year);
$_ = $format;
s/%%/%/g;
s/%sql/$yearl-$monl-$mdayl/g;
s/%a/$short_wday/g;
s/%A/$WEEK_DAYS[$wday]/g;
s/%b|%h/$short_mon/g;
s/%B/$MONTHS[$mon-1]/g;
s/%c/$full_en_text_date/g;
s/%d/$mdayl/g;
s/%D|%x/$monl\/$mday\/$year/g;
s/%e/$mday/g;
s/%m/$monl/g;
s/%H/$hour/g;
s/%j/$yday/g;
s/%M/$min/g;
s/%S/$sec/g;
s/%n/\n/g;
s/%t/\t/g;
s/%X|%T/$hour:$min:$sec/g;
s/%y/$year/g;
s/%Y/$yearl/g;
return $_;
} |
Partager