从现在到将来的时间。(天小时分钟秒)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从现在到将来的时间。(天小时分钟秒)相关的知识,希望对你有一定的参考价值。
modified version of:http://www.linein.org/blog/2008/04/04/find-time-between-two-dates-in-php/
function timeBetweenNowAndDeadline($deadline) { $diff = $deadline-$currentDate; $seconds = 0; $hours = 0; $minutes = 0; if($diff % 86400 <= 0){$days = $diff / 86400;} // 86,400 seconds in a day if($diff % 86400 > 0) { $rest = ($diff % 86400); $days = ($diff - $rest) / 86400; if($rest % 3600 > 0) { $rest1 = ($rest % 3600); $hours = ($rest - $rest1) / 3600; if($rest1 % 60 > 0) { $rest2 = ($rest1 % 60); $minutes = ($rest1 - $rest2) / 60; $seconds = $rest2; } else{$minutes = $rest1 / 60;} } else{$hours = $rest / 3600;} } if($days > 0){$days = $days.'d, ';} else{$days = false;} if($hours > 0){$hours = $hours.'h, ';} else{$hours = false;} if($minutes > 0){$minutes = $minutes.'m, ';} else{$minutes = false;} $seconds = $seconds.'s'; // always be at least one second return $days.''.$hours.''.$minutes.''.$seconds; }
以上是关于从现在到将来的时间。(天小时分钟秒)的主要内容,如果未能解决你的问题,请参考以下文章
PostgreSQL:包含秒到小时分钟秒天间隔 SECONDSDIFF 的列