2008-02-21から1日間の記事一覧

3.5 2つの日付の差を求める

# 方法1 $seconds = $recent - $earlier

3.4 日付や時刻を加算/減算する

$when = $now + $difference $then = $now - $difference

3.3 エポック秒をDMYHMS形式の値に変換したい

# 方法 ($seconds, $minutes, $hour, $day_of_month, $month, $year, $wday, $yday, $isisdst) = localtime($time);

3.2 DMYHMS形式の値をエポック秒に変換する

use Time::Local; $time = timelocal($sec, $min, $hours, $mday, $mon, $year); $time = timegm($sec, $min, $hours, $mday, $mon, $year);

3.1 今日の日付を取得する

# 方法1 ($day, $month, $year) = (localtime)[3,4,5]; # 方法2 use Time::localtime; $tm = localtime; ($day, $month, $year) = ($tm->mday, $tm->mon, $tm->year);

2.17 正しい複数形を出力する

printf "It took %d hour%s\n", $time, $time == 1 ? "" : "s"; printf "%d hour%s %s enough.\n", $time, $time == 1 ? "" : "s", $time == 1 ? "is" : "are";

2.16 数値の位取りのカンマを挿入する

sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,g; return scalar reverse $text; }