gpt4 book ai didi

php - 如何在php中获取前3个月的数据

转载 作者:行者123 更新时间:2023-12-02 12:05:03 26 4
gpt4 key购买 nike

如何在 php ex 中获取前 3 个月(如果我说 DEC..它应该显示前 3 个月,即 OCT NOV DEC)

最佳答案

您可以使用strtotime功能如下:

echo date('M', strtotime('-3 month'));

因此,您可以用减号指定之前的日期。

echo date('M', strtotime('0 month'));
echo date('M', strtotime('-1 month'));
echo date('M', strtotime('-2 month'));
echo date('M', strtotime('-3 month'));

结果:

Dec
Nov
Oct
Sep
<小时/>

如果您使用这样的循环,您可以执行相同的操作:

for ($i = -3; $i <= 0; $i++){
echo date('M', strtotime("$i month"));
}

结果:

Sep
Oct
Nov
Dec
<小时/>

查看文档也可以看到许多其他友好的日期和时间关键字 strtotime 支持:

关于php - 如何在php中获取前3个月的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4497199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com