PR

日時取得

日時取得に関する過去の覚書。

スポンサードリンク

perl > 日時取得

日時取得、計算スクリプト

もくじ

※ちなみに現在はこの方法を使ってない。モジュール移行に際して不要になったものの覚書なので。

■ 「年」を取得

宣言

use Time::Local;

取得方法

my $year = &GetYear;

ルーチン

sub GetYear{
my(undef, undef, undef, undef, undef, $year) = localtime(time);
$year += 1900;
return $year;
}

上へ

■ 「月」を取得

宣言

use Time::Local;

取得方法

my $month = &GetMonth;

ルーチン

sub GetMonth{
my(undef, undef, undef, undef, $month, undef) = localtime(time);
$month += 1;
return sprintf(“%02d”, $month);
}

上へ

■ 「日」を取得

宣言

use Time::Local;

取得方法

my $today = &GetDate;

ルーチン

sub GetDate{
my(undef, undef, undef, $day, undef, undef) = localtime(time);
return sprintf(“%02d”, $day);
}

上へ

■ 「曜日」配列番号の取得

宣言

use Time::Local;

取得方法

自分で作っといて忘れた
たぶん

my $wday = &GetWeek;

ルーチン

sub GetWeek{
my(undef, undef, undef, undef, undef, undef, $wday) = localtime(time);
return $wday;
}

取得した配列番号の対応する曜日

0
1
2
3
4
5
6

コメント