ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ /** * 获取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) 获取的时间戳为当前时间戳的前一天