doushenxu7294 2014-07-12 14:19 采纳率: 0%
浏览 124

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

This question already has an answer here:

I need to round the actual date/time to nearest past 15 min. and calculate the 10 previous 15 min times.

For ex. 12/07/2014 16:25 should be rounded to 12/07/2014 16:15 and i must retrieve 12/07/2014 16:00, 15:45, 15:30, etc... It must keep track of hour,day,month, year/leap year. I need all variables year/month/day/hour/minutes.

What is the easiest way to do that ? php or javascript ? any working script ?

I scratching my head...

</div>
  • 写回答

1条回答 默认 最新

  • douwang6635 2014-07-12 14:26
    关注

    You can try something like this

    $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) ;
    

    Output:

    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 ) 
    
    评论

报告相同问题?