Using PHP how do you get the number of seconds elapsed since midnight of the current day?
All i've tried right now is:
$hour=substr(date("h:i:s"),0,2);
$minute=substr(date("h:i:s"),3,2);
echo $hour."\r\n";
echo $minute."\r\n";
...but it doesn't return the correct server time of the response and I don't know how to do that.
This should work.
This will only show your servers timezone though.
In Carbon, the number of seconds elapsed since midnight can be found like this:
$seconds_since_midnight = $dt->secondsSinceMidnight()
;And though there's no minutes since midnight I suppose you do:
$minutes_since_midnight = (int) floor($dt->secondsSinceMidnight()/60);
I think you want to get time from start of the day to current hours and seconds of the day, this can be done like this, you will still need to set your timezone time in place of 'Asia/Karachi'. This gets correct time since midnight in user's timezone instead of server's timezone time.
Here is working link: http://codepad.viper-7.com/ykJC2R
Simplest I believe would be dividing the current time (in seconds) by the number of seconds in a day (60*60*24) and taking the remainder: