如何从PHP日期时间获取unix时间戳?

时间:2021-12-22 16:00:17

I'm trying to get a unix timestamp with PHP but it doesn't seem to be working. Here is the format I'm trying to convert to a unix timestamp:

我正在尝试使用PHP获取unix时间戳,但它似乎不起作用。这是我想要转换为unix时间戳的格式:

PHP

$datetime = '2012-07-25 14:35:08';

$unix_time = date('Ymdhis', strtotime($datetime ));
echo $unix_time;

My result looks like this:

我的结果如下:

20120725023508

Any idea what I'm doing wrong?

知道我做错了什么吗?

2 个解决方案

#1


26  

strtotime Returns a timestamp on success, FALSE otherwise.

strtotime返回成功时间戳,否则返回FALSE。

 echo strtotime('2012-07-25 14:35:08' );

Output

1343219708

#2


3  

This is converting it to a unix timestamp: strtotime($datetime), but you're converting it back to a date again with date().

这是将它转换为unix时间戳:strtotime($ datetime),但是你用date()再次将它转换回日期。

#1


26  

strtotime Returns a timestamp on success, FALSE otherwise.

strtotime返回成功时间戳,否则返回FALSE。

 echo strtotime('2012-07-25 14:35:08' );

Output

1343219708

#2


3  

This is converting it to a unix timestamp: strtotime($datetime), but you're converting it back to a date again with date().

这是将它转换为unix时间戳:strtotime($ datetime),但是你用date()再次将它转换回日期。