戻る

解答例

PHP

<?php
header("Content-type: text/html; charset=utf-8");

date_default_timezone_set("Asia/Tokyo");

echo "strtotime()関数による時間比較<br>";
$start = strtotime("now");
echo "開始時のタイムスタンプ" . $start . "<br>";
for($i = 0; $i < 50000000; $i++){
	//
}

$end = strtotime("now");
echo "終了時のタイムスタンプ" . $end . "<br>";

echo ($end - $start) . "秒経過しました!<br><br>";

echo "time()関数による時間比較<br>";
$start = time();
echo "開始時のタイムスタンプ" . $start . "<br>";
for($i = 0; $i < 50000000; $i++){
	//
}
$end = time();
echo "終了時のタイムスタンプ" . $end . "<br>";
echo ($end - $start) . "秒経過しました!<br><br>";


echo "mktime()関数による日数比較<br>";
//2006年9月1日
$timestamp1 = mktime(0,0,0,9,1,2006);

//2006年9月5日
$timestamp2 = mktime(0,0,0,9,5,2006);

//差を計算
echo ($timestamp2 - $timestamp1) / (60 * 60 * 24) . "日の違いがあります!"
?>

inserted by FC2 system