PHP break time on current day

How to find out how much time is left to complete the current day from the current time [date ('Ymd H: i: s')] in PHP.

+3
source share
3 answers

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, it mktime(24,0,0)also works:

$left = mktime(24,0,0) - time();
+6
source
$time_in_seconds = (24*3600) - (date('H')*3600 + date('i')*60 + date('s'));

Calculates the full seconds of one day and subtracts the seconds elapsed before the current hour of the day.

0
source

In Javascript for anyone interested (taking into account time zone 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;
}
0
source

Source: https://habr.com/ru/post/1747651/


All Articles