Hatena::Groupshoma

ハズレmemo

2007-05-24

[] Time::Localのyear

use Time::Local;
use Data::Dumper;
use POSIX qw/strftime/;

$t = timelocal(0,0,0, 1, 4-1, 7);
print Dumper(strftime("%Y/%m/%d", localtime($t)));

$t = timelocal(0,0,0, 1, 4-1, 07);
print Dumper(strftime("%Y/%m/%d", localtime($t)));

$t = timelocal(0,0,0, 1, 4-1, 107);
print Dumper(strftime("%Y/%m/%d", localtime($t)));

$t = timelocal(0,0,0, 1, 4-1, 2007);
print Dumper(strftime("%Y/%m/%d", localtime($t)));

出力。

$VAR1 = '2007/04/01';

$VAR1 = '2007/04/01';

$VAR1 = '2007/04/01';

$VAR1 = '2007/04/01';

これは

Your mileage may vary when trying these with minutes and hours, and it
doesn't work at all for months.

Strictly speaking, the year should also be specified in a form consis-
tent with localtime(), i.e. the offset from 1900.  In order to make the
interpretation of the year easier for humans, however, who are more
accustomed to seeing years as two-digit or four-digit values, the fol-
lowing conventions are followed:

o   Years greater than 999 are interpreted as being the actual year,
   rather than the offset from 1900.  Thus, 1963 would indicate the
   year Martin Luther King won the Nobel prize, not the year 3863.

o   Years in the range 100..999 are interpreted as offset from 1900, so
   that 112 indicates 2012.  This rule also applies to years less than
   zero (but see note below regarding date range).

o   Years in the range 0..99 are interpreted as shorthand for years in
   the rolling "current century," defined as 50 years on either side
   of the current year.  Thus, today, in 1999, 0 would refer to 2000,
   and 45 to 2045, but 55 would refer to 1955.  Twenty years from now,
   55 would instead refer to 2055.  This is messy, but matches the way
   people currently think about two digit dates.  Whenever possible,
   use an absolute four digit year instead.

The scheme above allows interpretation of a wide range of dates, par-
ticularly if 4-digit years are used.

のため。

よって、22世紀になる際には注意。