Is there a native way of doing "HH:MM:SS" to seconds
with PHP 5.3 rather than doing a split on the colon's and multipling out each section the relevant number to calculate the seconds?
For example in Python you can do :
string time = "00:01:05";
double seconds = TimeSpan.Parse(time).TotalSeconds;
This should do the trick:
Unfortunately not - as PHP isn't strongly typed there's no concept of a time type and hence no means to convert between such a string and a "seconds" value.
As such, in practice people often split the string and multiply out each section as you mentioned.
The quick way:
I think the easiest method would be to use
strtotime()
function:demo
Function
date_parse()
can also be used for parsing date and time:demo