企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# strtotime函数 >[success] strtotime — 将任何字符串的日期时间描述解析为 Unix 时间戳 ## 函数原型 ~~~ int strtotime ( string $time [, int $now = time() ] ) ~~~ ## 参数说明 >[info] time 日期/时间字符串。正确格式的说明详见 日期与时间格式。 now 用来计算返回值的时间戳。 ## 返回值 >[info] 成功则返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前本函数在失败时返回 -1。 >[danger] 使用 strtotime() 函数将一个字符串表达的日期时间转换为时间戳。 另外,一些数据库产品也提供了将日期时间格式转换为时间戳的函数。 (例如 MySQL 中的 » UNIX_TIMESTAMP 函数)。 > # 应用 >[success]日期增加 ## 当前时间戳增加一年 ~~~ echo strtotime("+1 year");//返回时间戳, 如果要转换成一般时间格式还需要下面的函数 echo date('Y-m-d H:i:s', strtotime("+1 year")); ============================================== 同理,不仅仅可以+year 还可以是天, 月日都可以的,如下代码: <?php 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"; echo date("Y-m-d", strtotime("+1 months", strtotime("2010-10-06"))), "\n"; ?> ~~~