PHP 中的 strtotime() 函数

phpprogrammingserver side programming更新于 2025/9/17 1:22:17

strtotime() 函数将英文文本日期或时间解析为 Unix 时间戳。成功时返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前的版本中,此函数失败时返回 -1。

语法

strtotime(time, now)

参数

  • time  − 指定要解析的时间字符串。

  • now  − 用于计算返回值的时间戳。

返回

strtotime() 函数成功时返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前,此函数在失败时将返回 -1。

示例

下面是一个例子 −

<?php
   $timestamp = strtotime( "June 20, 2018" ); print date( 'Y-m-d', $timestamp );
?>

输出

2018-06-20

示例

让我们看另一个例子 −

<?php
   echo(strtotime("now") . "<br>");
   echo(strtotime("10 March 2018") . "<br>");
   echo(strtotime("+10 hours") . "<br>");
?>

输出

1539235161
1520640000
1539271161

相关文章