如何从一个时代中获得秒数

时间:2014-09-05 09:46:57

标签: php

我喜欢从像11.5 years这样的字符串中获取秒数。使用strtotime()返回负值

strtotime('11.5 years', 0)

解释为here

3 个答案:

答案 0 :(得分:2)

echo strtotime('+11 years 6 months');

<强> Fiddle

答案 1 :(得分:1)

你可以试试这个:

echo strtotime('+11 years 6 months');

答案 2 :(得分:0)

我提出了适用于我的应用程序的解决方案

$value = 11.5;
$unit = 'year'; //day, second, month,...

$integer = floor($value);
$decimal = $value-$integer;

               //get value of full [unit] and at the percentage from the decmail
$delay = strtotime('+'.$integer.' '.$unit, 0)+strtotime('+1 '.$unit, 0)*$decimal