Thread Aktuelles Datum in Variable (17 answers)
Opened by Fairy at 2012-05-07 10:27

Linuxer
 2012-05-07 11:34
#158122 #158122
User since
2006-01-27
3875 Artikel
HausmeisterIn

user image
2 einfache Subroutinen, die Datum bzw. Zeit als String zurückliefern:

Code (perl): (dl )
1
2
3
4
5
6
7
# return date as string in format: YYYYMMDD
sub date2str {
    # see 'perldoc -f localtime' for details
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime;

    return sprintf "%04d%02d%02d", $year+1900, $mon+1, $mday;
}

Code (perl): (dl )
1
2
3
4
5
6
# return time as string in format: hhmmss
sub time2str {
    my ( $sec, $min, $hour ) = localtime;

    return "%02d%02d%02d", $hour, $min, $sec;
}
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Aktuelles Datum in Variable