如何从 PHP 日期时间获取 unix 时间戳? [英] How do I get a unix timestamp from PHP date time?

查看:46
本文介绍了如何从 PHP 日期时间获取 unix 时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我的结果是这样的:

20120725023508

知道我做错了什么吗?

推荐答案

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

strtotime Returns a timestamp on success, FALSE otherwise.

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

输出

1343219708

这篇关于如何从 PHP 日期时间获取 unix 时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆