in reply to Need Help with DATE::CALC $doy
Time::Local only converts Y/M/D,H:M:S to epoch seconds, but you can very easily extract out the month and day components from the epoch time with localtime:use Time::Local 'timelocal_nocheck'; my $year = 2003 - 1900; my $dyear = 176; my $epoch = timelocal_nocheck 0,0,0,$dyear,0,$year; ## January is month 0 ^
.. or you could format the date with whatever format you like, using strftimemy ($month, $day) = (localtime $epoch)[4,3]; $month++; ## again, months run from 0 to 11
For doing simple date calculations like this, using localtime and Time::Local is a lot less overhead than the behemoth Date::Calc.use POSIX 'strftime'; print strftime("%x", localtime $epoch), $/;
UPDATE: If you only care about getting the text output (you don't need the day/month components individually), it looks like strftime also normalizes its input in the same way as timelocal_nocheck:
Also realized that I needed to use 2003-1900 (not just 2003) as the final argument to timelocal_nocheck, so updated that.$ perl -MPOSIX=strftime -le 'print strftime("%c", 0,0,0,176,0,103)' Thu Jun 25 00:00:00 2003
blokhead
|
|---|