Use DateTime. It's much better for date math.
$tomorrow = new DateTime('tomorrow');
$now = new DateTime();
$diff = $tomorrow->diff($now);
echo $diff->format("%h hours, %i minutes, %s seconds");
// 7 hours, 12 minutes, 53 seconds
Frage
I'm trying to do a simple countdown, but it's giving the wrong time:
$time_seconds_view = strtotime('tomorrow') - time(); echo date("H" . " \h\o\u\\r\s\, " . "i" . " \m\i\\n\u\\t\\e\s\, \a\\n\d " . "s" . " \s\\e\c\o\\n\d\s", $time_seconds_view);
is spitting out 00 hours, 30 minutes, and 00 seconds
even though date_default_timezone_set($this->session->userdata('timezone'));
is set to America/Phoenix
it should be spitting out 07 hours, 30 minutes, and 00 seconds
it's as if PHP is not taking account that I've changed the default timezone.
Anything I'm doing wrong? Thanks for your help!
Lösung
Use DateTime. It's much better for date math.
$tomorrow = new DateTime('tomorrow');
$now = new DateTime();
$diff = $tomorrow->diff($now);
echo $diff->format("%h hours, %i minutes, %s seconds");
// 7 hours, 12 minutes, 53 seconds