戻る

解答例

PHP

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

date_default_timezone_set("Asia/Tokyo");

echo "現在の日時<br>";
echo date("Y/m/d H:i:s") . "<br><br>";

echo "1年後の日付<br>";
echo date("Y/m/d", strtotime("+1 year")) . "<br><br>";

echo "1ヶ月後の日付<br>";
echo date("Y/m/d", strtotime("+1 month")) . "<br><br>";

echo "1日後の日付<br>";
echo date("Y/m/d", strtotime("+1 day")) . "<br><br>";

echo "3日前の日付<br>";
echo date("Y/m/d", strtotime("-3 day")) . "<br><br>";

echo "前の日曜日の日付<br>";
echo date("Y/m/d", strtotime("last Sunday")) . "<br><br>";

echo "次の日曜日の日付<br>";
echo date("Y/m/d", strtotime("next Sunday")) . "<br><br>";

echo "5時間前の時刻<br>";
echo date("H:i:s", strtotime("-5 hours")) . "<br><br>";

echo "1分後の時刻<br>";
echo date("H:i:s", strtotime("+1 minutes")) . "<br><br>";

echo "1秒後の時刻<br>";
echo date("H:i:s", strtotime("+1 seconds")) . "<br><br>";

echo "2006年9月1日の前日<br>";
$timestamp = mktime(0,0,0,9,1,2006);
echo date("Y/m/d", strtotime("-1 day, $timestamp"));
?>

inserted by FC2 system