PHP Add Seconds
For the life outta me, I checked through-out this forum and follow instruction, might have overlooked a thing or two.
Using:
$today = date("m/d/Y h:i:s A");
This will show me the accurate today's date/time, which I'm happy however, I'm trying to add seconds to the current date/time but keep giving me odd results.
$lSec = intval($str);
$lDay = intva开发者_C百科l($lSec / 86400);
$lHou = intval($lSec / 3600);
WHILE ($lHou >= 24) {
$lHou = $lHou-24;
};
$lMin = intval(($lSec / 60) % 60);
$lSec = intval($lSec % 60);
return date(
"m-d-Y H:i:s A",
mktime(
date("H")+$lHou,
date("i")+$lMin,
date("s")+$lSec,
date("m")+0,
date("d")+$lDay,
date("Y")+0
)
);
Is there anything I'm missing or is there anything better than this? I even tried date_add and not giving me desirable result either.
Thanks!
P.S. Running on web host IIS7 with PHP 5 support.
Try adding seconds to time()
$today = date( "m/d/Y h:i:s A", time() + 3600 ); // + 1 hour
You want to add intval($str)
seconds to the current time, and format the resulting date?
date("m/d/Y h:i:s A", time() + intval($str));
time
gives the current time in seconds, and date
accepts a time in seconds.
$dateval= "04/07/2016 6:58:00";
$endDate=date('Y-m-d H:i:s',strtotime("+1 seconds",strtotime($dateval)));
Add 30 seconds from right now:
$halfMinuteLater = strtotime("+30 seconds");
$formmatedTime = date('H:i:s', $halfMinuteLater);
精彩评论