PHP中strtotime()函数使用

这个函数的作用是传入一定文本格式的参数,返回一个时间戳,可以使用它来获取一个时间戳,比如获取前一天,前一个月,前一年等等。

这个函数的使用场景非常多,比如查询一个月内的数据,查询一天内的数据。

语法

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

参数

例子

// 琼台博客 www.qttc.net

echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
// 琼台博客 www.qttc.net

echo date("jS F, Y", strtotime("11.12.10")); 
// outputs 10th December, 2011 

echo date("jS F, Y", strtotime("11/12/10")); 
// outputs 12th November, 2010 

echo date("jS F, Y", strtotime("11-12-10")); 
// outputs 11th December, 2010  
// 琼台博客 www.qttc.net

echo date( "Y-m-d", strtotime( "2009-01-31 +1 month" ) ); // PHP:  2009-03-03
echo date( "Y-m-d", strtotime( "2009-01-31 +2 month" ) ); // PHP:  2009-03-31
分享

TITLE: PHP中strtotime()函数使用

LINK: https://www.qttc.net/30-php-strtotime.html

NOTE: 原创内容,转载请注明出自琼台博客