如何转换"HH:MM:SS"字符串到秒用PHP? [英] How to convert a "HH:MM:SS" string to seconds with PHP?
本文介绍了如何转换"HH:MM:SS"字符串到秒用PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种本机的方法可以使用PHP 5.3进行"HH:MM:SS" to seconds
而不是在冒号上进行拆分,并在每个部分中乘以相关的数字以计算秒数?
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?
例如,在Python中,您可以执行以下操作:
For example in Python you can do :
string time = "00:01:05";
double seconds = TimeSpan.Parse(time).TotalSeconds;
推荐答案
快速方法:
echo strtotime('01:00:00') - strtotime('TODAY'); // 3600
这篇关于如何转换"HH:MM:SS"字符串到秒用PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文