获取30天前的日期并转换为iso8601格式

Getting the date from 30 days ago and converting to iso8601 format

我正在尝试获取 30 天前的日期并确保它是 iso8601 格式以便在亚马逊 MWS 中使用这是我尝试过的方法,它在一定程度上有效而且看起来就像在正确的格式,但亚马逊仍然说它不正确!

$tester = date("c");
$tester = date('Y-m-d H:i:s', strtotime($tester . ' -30 days'));
$datetime = urlencode($tester);
echo $datetime;

您需要指定"c":

$tester = date('c', strtotime('-30 days'));
// if current  date is: 2018-05-02T13:53:24+05:00
// the result would be: 2018-04-02T13:53:24+05:00

话虽如此,我建议切换到 DateTime class:

$date = new DateTime();               // create date for current date
$date->sub(new DateInterval("P30D")); // subtract 30 days
echo $date->format("c");              // 2018-04-02T13:57:54+05:00