Perlの現在年月日時刻は以下のようにして取得できます。

use strict;
use warnings;
use utf8;
 
# 時刻情報を全部取得して整形
my ($sec,  $min,  $hour, 
	$mday, $mon,  $year, 
	$wday, $yday, $isdst) = localtime();
 
print sprintf("%04d/%02d/%02d %02d:%02d:%02d",
               $year+1900,
               $mon+1,
               $mday,
               $hour,
               $min,
               $sec);

ただ年月日しか必要ない時でも上記のように書いていて、ムダな変数ができちゃうなぁと思っていたのですが、以下のようにすれば良かったのですね。

use strict;
use warnings;
use utf8;

# 年月日の時刻情報のみ取得
my ($mday, $mon, $year) = (localtime)[3,4,5];

print sprintf("%04d/%02d/%02d",
			   $year+1900,
			   $mon+1,
			   $mday);

絶対あとで忘れる自信があるのでメモしておきます。

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>