Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Today I find following perl script running incorrect. Current actual datetime is 20140814 13:19 But it returns: 2014-7-14-13-19-15 (the month value 7 is 1 less than actual value 8)

MY OS: win7

sub GetFileNameDate {
    my ($sec,$min,$hour,$day,$month,$yr19,@rest) =   localtime;
    return sprintf "%s-%s-%s-%02d-%02d-%02d", ($yr19 + 1900), $month, $day, $hour, $min, $sec;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
158 views
Welcome To Ask or Share your Answers For Others

1 Answer

It is not incorrect it is like the month values starts from 0

sub GetFileNameDate {
    my ($sec,$min,$hour,$day,$month,$yr19,@rest) =   localtime;
    return sprintf "%s-%s-%s-%02d-%02d-%02d", ($yr19 + 1900), ($month +1), $day, $hour, $min, $sec;
}

$month is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December.

You can check the manual


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...