【问题标题】:Convert epoch to days将纪元转换为天
【发布时间】:2017-11-16 11:41:37
【问题描述】:

我有以下代码:

<?php
function cuantosdias($d){
    $d = strtotime($d);
    $c = strtotime("now");
    $e = $c - $d;
    return $e;
};
$fecha = "13-10-2016 00:00:00";
$cant = cuantosdias($fecha);
echo $cant/86400 . "\n";

我得到两个日期之间的天数。

我想知道如何获得 $cant 格式:d H:i:s。

有这样的功能吗?

【问题讨论】:

标签: php date


【解决方案1】:

简单来说,你可以这样试试:

<?php

$fecha = "13-10-2016 00:00:00";

function dateDifference($date, $differenceFormat = '%y year(s) %m month(s) %d day(s) %H:%i:%s' )
{
    $datetime1 = date_create($date);
    $datetime2 = date_create();
    $interval = date_diff($datetime1, $datetime2);

    return $interval->format($differenceFormat);

}

echo dateDifference($fecha);

【讨论】:

    猜你喜欢
    • 2010-09-13
    • 2011-03-14
    • 2017-02-20
    • 1970-01-01
    • 2016-10-18
    • 2011-08-17
    • 2015-03-17
    • 2017-12-20
    相关资源
    最近更新 更多