PHP gets 00:00:00 unix timestamp
If I got unix time like
1407050129
How to get 12:00 AM of this unix day in unix timestamp means the first minute of the day of this unix time.
Example, if I want to get the first minute today
$today_first_min = strtotime("00:00:00");
+3
user3504335
source
to share
2 answers
Try the following:
$that_day = "1407050129";
$that_day_first_min = strtotime(date('Y-m-d', $that_day) . ' midnight');
See demo
+5
Mark miller
source
to share
An alternative method to get the same result ... Unix time is the number of seconds since 1970-01-01 00:00:00 UTC, so every whole day is a multiple of (60 * 60 * 24) seconds.
Using this fact, you can use the modulus (%) to calculate and then remove the remainder (i.e. seconds, hours, and minutes) from the day and go back to the first hours!
date_default_timezone_set('UTC');
$that_date = 1407050129;
$first_hour = $that_date - ($that_date % (60*60*24));
print date('Y-m-d H:i:s', strval($first_hour));
// 2014-08-03 00:00:00
+2
msturdy
source
to share