Reputation: 5232
I need to get the remaining seconds in the actual hour for caching weather-data. What's the most efficient method of doing that?
Upvotes: 0
Views: 103
Reputation: 1025
Simply use PHP's time function as follows:
<?php
function getSecondsRemaining()
{
//Take the current time in seconds since the epoch, modulus by 3600 to get seconds in the hour, then subtract this from 3600 (# secs in an hour)
return 3600 - time() % (60*60);
}
?>
This should get you the performance you want.
Upvotes: 4
Reputation: 1747
How about
$date = new DateTime("now");
$seconds_left = ( ( 59 - $date->format("i") ) * 60 ) + ( 60 - $date->format("s") );
Upvotes: 0
Reputation: 357
Here you go mate:
$currentMinute = date("i");
$minuteLeft = 60 - $currentMinute;
$secondLeft = $minuteLeft * 60;
$secondLeft += date("s");
echo $secondLeft;
Upvotes: 1