【问题标题】:PHP gmdate to timestampPHP gmdate 到时间戳
【发布时间】:2014-11-03 01:45:28
【问题描述】:

我有一个格式如下的日期字符串 1970 年 1 月 1 日,我无法将其转换回时间戳格式

我尝试过使用 Datetime 无济于事

$test=new DATETIME($expire_date);
echo date_timestamp_get( $test);

我知道这是使用代码制作的

<?php
gmdate("F j, Y", $date_created)

如何将其格式化回时间戳,以便与今天的日期进行比较 例如

<?php
if (time()>$timestamp){
//do something
}

【问题讨论】:

  • 你可以使用 gmddate()

标签: php date


【解决方案1】:

您需要将DateTime::format()U 参数一起使用,因为$test 是DateTime 对象而不是常规日期字符串:

$timestamp = $test->format('U');

或者,更好的是,只比较 DateTime 对象(我更改了变量名称以使 ode 更易于阅读):

$expires = new DateTime($expire_date);
$now     = new DateTime();

if ($now > $expires){
//do something
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    相关资源
    最近更新 更多