开发者

Is it possible to get UNIX time from such date 2011-02-27 02:04:46? [duplicate]

This question already has answers here: How to convert date to timestamp in PHP? 开发者_开发百科 (22 answers) Closed 9 years ago.

Mktime and other functions give wrong answer for such a date like 2011-02-27 02:04:46;


Just use the strtotime() function, or the DateTime class.


Both the two following portions of code :

echo strtotime('2011-02-27 02:04:46');

$dt = new DateTime('2011-02-27 02:04:46');
echo $dt->format('U');

Will give you the same output :

1298768686


Use strtotime

$time = '2011-02-27 02:04:46';
strtotime($time);


This will also work (if you need this to run from the unix shell):

date +%T

This will show the time like:

14:20:18
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜