/* * dateBy15Minutes * @assert ("2001-03-10 17:16:18") == "2001-03-10 17:15:00" * @assert ("2001-03-10 17:00:00") == "2001-03-10 17:00:00" * @assert ("2001-03-10 17:59:59") == "2001-03-10 17:45:00" * @assert ("2001-03-10 17:40:18") == "2001-03-10 17:30:00" */ protected function _dateBy15Minutes($mode = 'ceil',$time = NULL) { if (\is_null($time)) { $time = time(); } else { $time = \strtotime($time); } if ($mode == 'ceil') { $minute = \sprintf("%02s", \ceil(\date('i') / 15) * 15); } else { $minute = \sprintf("%02s", \floor(\date('i') / 15) * 15); } $time_string = \date("Y-m-d H:i:s", \mktime(\date('H'), $minute)); return $time_string; }
19 Nov 2014
[PHP]時間を15分刻みに変換する
覚え書きの殴り書き。
時間を15分刻みに変換する。切り上げ、切り捨てありです。