Reputation: 7109
How can we find out how many time remains to end the current day from current time[date('Y-m-d H:i:s')] in PHP.
Upvotes: 3
Views: 2399
Reputation: 4793
In Javascript, for anyone interested (takes care of timezone differences) :
var now=new Date();
var d=new Date(now.getYear(),now.getMonth(),now.getDate(),23-now.getHours(),59-now.getMinutes(),59-now.getSeconds()+1,0);
document.write(checkTime(d.getHours()) + ':' + checkTime(d.getMinutes()) + ':' + checkTime(d.getSeconds()) + ' time left');
function checkTime(i) {
if (i<10)
{
i="0" + i;
}
return i;
}
Upvotes: 0
Reputation: 816730
For example with a combination of mktime()
and time()
:
$left = mktime(23,59,59) - time() +1; // +1 adds the one second left to 00:00
Update:
From Simon's suggestion, mktime(24,0,0)
works too:
$left = mktime(24,0,0) - time();
Upvotes: 6
Reputation: 9365
$time_in_seconds = (24*3600) - (date('H')*3600 + date('i')*60 + date('s'));
Calculates the total seconds of one day and subtracts the seconds passed until the current hour of the day.
Upvotes: 0