获取上个月的日期在php [英] Getting last month's date in php

查看:311
本文介绍了获取上个月的日期在php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得上个月的日期。我写了这个:

I want to get last month's date. I wrote this out:

$prevmonth = date('M Y');

哪个给我当前的月份/年。我不知道是否应该使用 strtotime mktime 。有时间戳的东西?我需要再添加一些内容才能重置,以便我的网站上的所有时间戳记的所有日期都不会设置为上个月。我正在尝试使用RTFM,但我很难想出这一点。

Which gives me the current month/year. I can't tell if I should use strtotime, mktime. Something to the timestamp? Do I need to add something afterwards to reset so that the date isn't set to last month throughout everything for all timestamps on my site? I'm trying to RTFM but it's hard for me to figure this out.

推荐答案

上个月的日期很简单<回覆日期(Ynj,strtotime(上个月的第一天)); p>

It's simple to get last month date

echo date("Y-n-j", strtotime("first day of previous month"));
echo date("Y-n-j", strtotime("last day of previous month"));

在11月3日返回

2014-10-1
2014-10-31

这篇关于获取上个月的日期在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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