PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : perl: localtime vertut sich im Jahr



nidhoegg
19-09-2007, 15:04
Halo, ich stehe gerade auf dem Schlauch, was die Funktion localtime betrifft.

($sec,$min, $hour, $mon, $year) = localtime();
$year += 1900;
print "\n--------------------\n";
print "$sec, $min, $hour, $mon, $year";
ergibt bei mir die Ausgabe: 35,15,19, 1908
Was läuft da falsch? Laut manpage ist das Feld für $year "the number of years since 1900, not just the last two digits of the year". Aber es stimmt ja weder das eine noch das andere? Hab ich was wichtiges übersehen?

Viele Grüße,

nidhoegg

jan61
19-09-2007, 18:34
Moin,

aus "perldoc -f localtime":

localtime EXPR
Converts a time as returned by the time function
to a 9-element list with the time analyzed for the
local time zone. Typically used as follows:

# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) =
localtime(time);
Nach $hour kommt also $mday, nicht $mon.

Korrekt aufgelöst sollte es also so aussehen:

jan@jack:~/tmp> perl -e 'my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = localtime(time);printf "%04d-%02d-%02d\n", $year+1900,$mon+1, $mday;'
2007-09-19Jan

nidhoegg
20-09-2007, 09:15
Moin,

aus "perldoc -f localtime":Nach $hour kommt also $mday, nicht $mon.

Korrekt aufgelöst sollte es also so aussehen:

jan@jack:~/tmp> perl -e 'my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = localtime(time);printf "%04d-%02d-%02d\n", $year+1900,$mon+1, $mday;'
2007-09-19Jan
huch, tatsächlich. Kommt davon, wenn man zu lange vor dem Problem sitzt und den Wald vor lauter Bäumen nicht sieht. :) Vielen Dank!

Gruß, nidhoegg