PHP的5个不同时代

Don*_*oce 0 php

我需要有5个这样的变量:

$time1 = "The time now -5 minutes";
$time2 = "The time now -10 minutes";
$time3 = "The time now -20 minutes";
$time4 = "The time now -30 minutes";
$time5 = "The time now -40 minutes";
Run Code Online (Sandbox Code Playgroud)

所以假设它是上午9点,$ time1应该是"上午8:55"

如果有人能帮我解决这个问题会很棒:)

提前感谢每一个提示,

卡米洛

Ric*_*ams 9

使用strtotime(),然后date()根据需要格式化,

$time1 = date("g:i A", strtotime("-5 mins")); // e.g. 8:55 AM
$time2 = date("g:i A", strtotime("-10 mins")); // e.g. 8:50 AM
// ...etc
Run Code Online (Sandbox Code Playgroud)