开发者

php work out time until a certain day

开发者 https://www.devze.com 2023-03-23 14:31 出处:网络
I have been trying to work out how to get the exact time to the second until a certain day and hour. I believe it is开发者_运维知识库 the time function in php but i cant seem to get my head around it.

I have been trying to work out how to get the exact time to the second until a certain day and hour. I believe it is开发者_运维知识库 the time function in php but i cant seem to get my head around it.

I am trying to spit it out in the following format 'dd:hh:mm:ss'

Thanks


You can use datediff for that http://www.php.net/manual/en/datetime.diff.php, and the following is how you use date to format it the way you want

http://php.net/date echo date("d:H:i:s");

EDIT:

if your php version doesn't permit, you could use:

function datediff($date) {
    return strtotime($date) - time();
}

echo datediff("2011-12-31 15:00");


echo date('d:H:i:s', mktime($hour, $minute, $second, $month, $day, $year));

Where mktime() returns a timestamp.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号