[英]How do you convert a time “duration” from a string value into an integer?
我有一堆代表时间间隔的字符串值,如下所示:
'1 hour'
, '1.5 hours'
, '30 minutes'
等。
我想将所有这些值转换为分钟数,因此上述内容将分别变为:
60
, 90
, 30
我一直在弄混Carbon\\Carbon
和PHP的strtotime()
函数,但是我不知道该怎么做。 这可能真的很简单吗?
$str = '1 hour';
$int1 = strtotime("+".$str)- strtotime("now");
$int1
将以秒为单位返回时间。 在这里它将返回3600
。 这将无法处理1.5 hours
类的分数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.