我想找到两个给定时间戳之间的日期,月份或年份差异,并以标准格式返回。我试过这个,
function cncunix($stamp)
{
$date = new DateTime("@$stamp");
echo $date->format('d') . "\n";
}
// function to convert timestamp
$m = time()+60*60*24;
$n = time();
$y = $m - $n;
cncunix($y);
答案 0 :(得分:0)
$time_a = 86400;
$time_b = 172800;
$total = $time_b - $time_a;
$days = floor($total/86400);
echo "The difference is $days day(s)"
$ days将为您提供向下舍入的天数。例如,2.5将变为2.如果您不想要,则删除楼层功能。
答案 1 :(得分:0)
为什么你不使用标准的php func?
<?php
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
答案 2 :(得分:0)
这很简单:
<?php
$m = time()+60*60*24;
$n = time();
$a = new DateTime();
$a->setTimestamp($m);
$b = new DateTime();
$b->setTimestamp($n);
echo $diff = $a->diff($b)->format("%a");
这是Eval