 |
(Terug) naar scripts op heeck.nl of heeck.nl
******************************************************************************************
timestamp
Deze perl subroutine pakt de output van 'time' en zet dat om naar één van de
formaten die in de hash %formats staan. Die is uiteraard nog fantasierijk uit te breiden,
met onder meer maand- en weekdagnamen.
Gebruiksvoorbeelden:
- $filedate = timestamp(((stat("$file"))[9]), "YYYYMMDDhhmm");
geeft 200510231436 b.v. voor gebruik in bestandsnamen e.d.
- $filedate = timestamp(((stat("$file"))[9]), "human");
geeft 23-10-2005 14:36 b.v. voor leesbare output naar de gebruiker.
01 sub timestamp{
02 # takes time, yes it does! Returns a formatted timestamp
03 my ($stamp, $formatting) = @_;
04 chomp $formatting;
05 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($stamp);
06 $year += 1900;
07 $year = sprintf("%.4u",$year);
08 $mon += 1;
09 $mon = sprintf("%.2u", $mon);
10 $mday = sprintf("%.2u", $mday);
11 $hour = sprintf("%.2u", $hour);
12 $min = sprintf("%.2u", $min);
13 my %formats = (
14 human => "$mday-$mon-$year $hour:$min",
15 YYYYMMDDhhmm => "$year$mon$mday$hour$min",
16 YYYYMMDDhh => "$year$mon$mday$hour",
17 YYYYMMDD => "$year$mon$mday",
18 YYYYMM => "$year$mon",
19 );
20 if ( defined $formats{$formatting} ){
21 return $formats{$formatting};
22 } else {
23 return $stamp;
24 }
25 }
* Begin **********************************************************************************
|
|  |