我在数据库如何做到这一点倒计时
我得到的当前日期的最后一天,让我们假设是UTC
class Datecalc
{
public $year;
public $month;
public $day;
public $hour;
public $min;
public $sec;
function diff($start,$end = false)
{
if($start > $end)
{
$this->day = 0;
$this->hour = "00";
$this->min = "00";
$this->sec = "00";
return false;
}
if(!$end) { $end = time(); }
if(!is_numeric($start) || !is_numeric($end)) { return false; }
$start = date('Y-m-d H:i:s',$start);
$end = date('Y-m-d H:i:s',$end);
$d_start = new DateTime($start);
$d_end = new DateTime($end);
$diff = $d_start->diff($d_end);
$this->year = $diff->format('%y');
$this->month = $diff->format('%m');
$this->day = $diff->format('%d');
$this->hour = $diff->format('%H');
$this->min = $diff->format('%I');
$this->sec = $diff->format('%S');
return true;
}
}
我用这个功能来计算时间差,但问题是我不能把天数计为99,而当日期是00:00:00,天-1,它的设置为98和时间23:59:59,在这个代码中它的一切都很好,但是如果天数高于30,重置为01,我想你明白我想说什么,请帮助!
换句话说我需要单独算日子,并需要绑定到天
它总是一个好主意,做日期计算与时间戳,因为你只有一个数字来处理,并可以转换时间戳后计算适当的天/月/任何字符串。 – Corubba 2012-02-13 15:09:47
将您的日期转换为EPOC标准,做差异,然后手动将其转换为月/日等。 – Mikhail 2012-02-13 15:13:18
哦,男士,我真的很困惑,你能给我一个帮助我理解的小例子吗? – 2012-02-13 15:14:58