Learning site for website creation
strtotime1

日付をタイムスタンプに変換:strtotime関数

公開日:2014年09月20日

strtotime関数

int strtotime ( string $time [, int $now = time() ] )

引数

time
日付/時刻 文字列
now
返される値を計算するために使用するタイムスタンプ 
省略時:1970 年 1 月 1 日 00:00:00 GMT からの通算秒

返り値

成功時:タイムスタンプ 失敗時:FALSE 
PHP 5.1.0 以前 失敗時: -1

記述例

//指定日時のタイムスタンプ
echo strtotime('2014-09-21 22:22:22');
//明日のタイムスタンプ
echo strtotime('1 day');
//昨日のタイムスタンプ
echo strtotime('-1 day');
//1週間後のタイムスタンプ
echo strtotime('1 week');
//1週間前のタイムスタンプ
echo strtotime('-1 week');
//1ヶ月後のタイムスタンプ
echo strtotime('1 month');
//1ヶ月前のタイムスタンプ
echo strtotime('-1 month');
//1年後のタイムスタンプ
echo strtotime('1 year');
//1年前のタイムスタンプ
echo strtotime('-1 year');
//1時間後のタイムスタンプ
echo strtotime('1 hour');
//30分後のタイムスタンプ
echo strtotime('30 min');
//30秒後のタイムスタンプ
echo strtotime('30 sec');
//1時間前のタイムスタンプ
echo strtotime('-1 hour');
//30分前のタイムスタンプ
echo strtotime('-30 min');
//30秒前のタイムスタンプ
echo strtotime('-30 sec');