Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: How to determine Unix Timestamp of midnight tomorrow?

I have the following code to determine the unix timestamp of midnight tomorrow. It seems pretty hacky to me and I wondered if anyone had a more elegant solution.

date("U", strtotime(date("Y-m-d 00:00:00", strtotime("tomorrow"))));
like image 247
Ben Mcmath Avatar asked Mar 10 '10 16:03

Ben Mcmath


1 Answers

This should be enough:

<?php
$t = strtotime('tomorrow');

You can also set a time:

<?php
$t = strtotime('tomorrow 14:55');

Please note that, as other date features in PHP, it will use the default time zone unless asked otherwise:

date_default_timezone_set('Asia/Tokyo');
$t = strtotime('tomorrow');
var_dump($t, date('r', $t));

date_default_timezone_set('Europe/Madrid');
$t = strtotime('tomorrow');
var_dump($t, date('r', $t));

date_default_timezone_set('Europe/Madrid');
// Generate midnight in New York, display equivalent Madrid time
$t = strtotime('tomorrow America/New_York');
var_dump($t, date('r', $t));
int(1502204400)
string(31) "Wed, 09 Aug 2017 00:00:00 +0900"
int(1502229600)
string(31) "Wed, 09 Aug 2017 00:00:00 +0200"
int(1502251200)
string(31) "Wed, 09 Aug 2017 06:00:00 +0200"
like image 180
Álvaro González Avatar answered Sep 25 '22 02:09

Álvaro González