多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ /** * 获取n天前的时间戳 * @param string $type 时间单位second|minute|hour|day|week|month|year * @param integer $some 时间数量 * @param [type] $time 时间戳 * @return [type] 设置后的时间戳 */ function get_time_ago($type = 'second', $some = 1, $time = null){ $time = empty($time) ? time() : $time; switch ($type) { case 'second': $result = $time - $some; break; case 'minute': $result = $time - $some * 60; break; case 'hour': $result = $time - $some * 60 * 60; break; case 'day': $result = strtotime('-' . $some . ' day', $time); break; case 'week': $result = strtotime('-' . ($some * 7) . ' day', $time); break; case 'month': $result = strtotime('-' . $some . ' month', $time); break; case 'year': $result = strtotime('-' . $some . ' year', $time); break; default: $result = $time - $some; } return $result; } ~~~ var_dump(get_time_ago('day',1,time())); **输出如下:** > int(1461835497) 获取的时间戳为当前时间戳的前一天