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

use*_*398 17 php unix-timestamp

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

PHP

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

$unix_time = date('Ymdhis', strtotime($datetime ));
echo $unix_time;
Run Code Online (Sandbox Code Playgroud)

我的结果如下:

20120725023508
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

Bab*_*aba 30

strtotime返回timestamp成功,否则返回FALSE.

 echo strtotime('2012-07-25 14:35:08' );
Run Code Online (Sandbox Code Playgroud)

产量

1343219708
Run Code Online (Sandbox Code Playgroud)

  • @Baba但是 strtotime 是特定于时区的,不是吗? (2认同)