开发者

How to convert 2010-03-01 to Unixtime (using php)

开发者 https://www.devze.com 2022-12-16 20:08 出处:网络
How ca开发者_如何学JAVAn I convert 2010-03-01 to unixtime such as 1267452738 (using php)?echo strtotime(\'2010-03-01\');

How ca开发者_如何学JAVAn I convert 2010-03-01 to unixtime such as 1267452738 (using php)?


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

An alternative is to use DateTime():

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

// PHP 5.5+
echo (new DateTime('2010-03-01'))->getTimestamp();


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

strtotime (PHP 4, PHP 5) — Parse about any English textual datetime description into a Unix timestamp

int strtotime ( string $time [, int $now ] )

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now , or the current time if now is not supplied.

This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 there are easier ways to define the timezone that is used across all date/time functions. That process is explained in the date_default_timezone_get() function page.


http://www.onlineconversion.com/unix_time.htm is also a good resource to convert unix time to date and vice versa.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号