从当前时间减去15分钟。 Javascript还是php?

时间:2014-07-12 14:19:22

标签: javascript php date time

我需要将实际日期/时间四舍五入到最近的15分钟。并计算前10次15分钟。

对于前。 12/07/2014 16:25应该四舍五入到2014年12月12日16:15我必须检索12/07/2014 16:00,15:45,15:30等... 它必须跟踪小时,日,月,年/闰年。我需要所有变量年/月/日/小时/分钟。

最简单的方法是什么? PHP或JavaScript?任何工作脚本?

我挠挠脑袋......

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情

$currentDT   = new \DateTime('2011-12-13 14:15:16');
print_r($currentDT);
echo '</br>';
$filterRange = new \DateInterval('PT15M');
$filterDate  = clone $currentDT;
$filterDate->sub($filterRange);
print_r($filterDate) ;

<强>输出:

DateTime Object ( [date] => 2011-12-13 14:15:16 [timezone_type] => 3 [timezone] => Europe/Berlin )
DateTime Object ( [date] => 2011-12-13 14:00:16 [timezone_type] => 3 [timezone] => Europe/Berlin ) 
相关问题