根据标题:如何在PHP中将字符串日期(YYYY-MM-DD)转换为纪元(从01-01-1970开始的秒数)
也许这就回答了你的问题
http://www.epochconverter.com/programming/functions-php.php链接的内容如下:
有很多选项:
- 使用"strtotime":
strtotime将大多数英语日期文本解析为epoch/Unix时间。
echo strtotime("15 November 2012");
// ... or ...
echo strtotime("2012/11/15");
// ... or ...
echo strtotime("+10 days"); // 10 days from now
检查转换是否成功是很重要的:
// PHP 5.1.0 or higher, earlier versions check: strtotime($string)) === -1
if ((strtotime("this is no date")) === false) {
echo 'failed';
}
2。使用DateTime类:
PHP 5的DateTime类使用起来更好:
// object oriented
$date = new DateTime('01/15/2010'); // format: MM/DD/YYYY
echo $date->format('U');
// or procedural
$date = date_create('01/15/2010');
echo date_format($date, 'U');
日期格式'U'将日期转换为UNIX时间戳。
- 使用"mktime":
这个版本比较麻烦,但是可以在任何PHP版本上运行。
// PHP 5.1+
date_default_timezone_set('UTC'); // optional
mktime ( $hour, $minute, $second, $month, $day, $year );
// before PHP 5.1
mktime ( $hour, $minute, $second, $month, $day, $year, $is_dst );
// $is_dst : 1 = daylight savings time (DST), 0 = no DST , -1 (default) = auto
// example: generate epoch for Jan 1, 2000 (all PHP versions)
echo mktime(0, 0, 0, 1, 1, 2000);
试试这个:
$date = '2013-03-13';
$dt = new DateTime($date);
echo $dt->getTimestamp();
裁判:http://www.php.net/manual/en/datetime.gettimestamp.php
使用strtotime()函数:
strtotime('2013-03-13');
使用strtotime()
,它提供了从01-01-1970开始的Unix时间戳