我怎样才能在php中获得上个月的名字 [英] how can i get previous month name in php

查看:55
本文介绍了我怎样才能在php中获得上个月的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

给定月份的下一个和上个月的php

我使用以下代码:

$prev_month = strtolower(date('F',strtotime('February - 1 month')));

总是返回12月,即使我将月份更改为3月。

and always return December even i change the month into March.

请帮助!

推荐答案

$currentMonth = date('F');
echo Date('F', strtotime($currentMonth . " last month"));

如果您不希望它相对于当前月份,则设置:

If you don't want it relative to the current month then set:

$currentMonth = 'February';
// outputs January

这篇关于我怎样才能在php中获得上个月的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆