Nic*_*rde 26
也许这回答了你的问题
http://www.epochconverter.com/programming/functions-php.php
以下是链接的内容:
有很多选择:
strtotime将大多数英语日期文本解析为epoch/Unix Time.
echo strtotime("15 November 2012");
// ... or ...
echo strtotime("2012/11/15");
// ... or ...
echo strtotime("+10 days"); // 10 days from now
Run Code Online (Sandbox Code Playgroud)
检查转换是否成功非常重要:
// PHP 5.1.0 or higher, earlier versions check: strtotime($string)) === -1
if ((strtotime("this is no date")) === false) {
echo 'failed';
}
Run Code Online (Sandbox Code Playgroud)
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');
Run Code Online (Sandbox Code Playgroud)
日期格式"U"将日期转换为UNIX时间戳.
这个版本更麻烦但适用于任何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);
Run Code Online (Sandbox Code Playgroud)
试试这个 :
$date = '2013-03-13';
$dt = new DateTime($date);
echo $dt->getTimestamp();
Run Code Online (Sandbox Code Playgroud)
参考:http://www.php.net/manual/en/datetime.gettimestamp.php