💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ $datetime1 = new DateTime(); $datetime2 = new DateTime('2018-08-16'); $interval = $datetime1->diff($datetime2); list($y, $m, $d) = explode('-', $interval->format('%Y-%m-%d')); echo "距世界杯还有{$y}年{$m}个月{$d}天"; $now=time(); $end=strtotime('2018-8-16 00:00:00'); $d=$end-$now; $y = date('Y', $d) - 1970; $m = date('n', $d) - 1; $d = date('j', $d) - 1; printf('还有%d年%d月%d天', $y, $m, $d); ~~~ ~~~ function getDiffTime($timestamp) { $datetime = new DateTime(date('Y-m-d H:i:s', $timestamp)); $datetime_now = new DateTime(); $interval = $datetime_now->diff($datetime); list($y, $m, $d, $h, $i, $s) = explode('-', $interval->format('%y-%m-%d-%h-%i-%s')); if ((($result = $y) && ($suffix = '年前')) || (($result = $m) && ($suffix = '月前')) || (($result = $d) && ($suffix = '天前')) || (($result = $h) && ($suffix = '小时前')) || (($result = $i) && ($suffix = '分钟前')) || (($result = $s) && ($suffix = '刚刚'))) { return $suffix != '刚刚' ? $result . $suffix : $suffix; } } ~~~