2

如何将 2010-03-01 转换为 unixtime,例如 1267452738(使用 php)?

4

3 回答 3

6
echo strtotime('2010-03-01');

另一种方法是使用DateTime()

// PHP 5.3+
$dt = new DateTime('2010-03-01');
echo $dt->getTimestamp();

// PHP 5.5+
echo (new DateTime('2010-03-01'))->getTimestamp();
于 2010-01-20T14:13:24.473 回答
0

http://php.net/manual/en/function.strtotime.php

strtotime (PHP 4, PHP 5) — 将任何英文文本日期时间描述解析为 Unix 时间戳

int strtotime ( 字符串 $time [, int $now ] )

该函数期望得到一个包含美国英语日期格式的字符串,并将尝试将该格式解析为 Unix 时间戳(自 1970 年 1 月 1 日 00:00:00 UTC 以来的秒数),相对于 now 中给出的时间戳,或者如果没有提供现在的当前时间。

此函数将使用 TZ 环境变量(如果可用)来计算时间戳。从 PHP 5.1.0 开始,有更简单的方法来定义所有日期/时间函数中使用的时区。该过程在 date_default_timezone_get() 函数页面中进行了说明。

于 2010-01-20T14:33:33.927 回答
0

http://www.onlineconversion.com/unix_time.htm也是将 unix 时间转换为日期的好资源,反之亦然。

于 2010-01-21T05:39:15.710 回答