【问题标题】:How to get YEAR of previous month using date()如何使用 date() 获取上个月的年份
【发布时间】:2012-07-20 09:55:57
【问题描述】:

我想得到上个月的年份。

例如在July 2012 我想要结果2012。 但是在January 2013 我想要结果2012Feb 2013 我想要结果2013

我已经搜索并找到了这个How to get previous month and year relative to today, using strtotime and date? 它使用date_create 函数(即DateTime 类)。但我想要一个不使用它的解决方案。即通过使用简单的date() 函数

【问题讨论】:

    标签: php


    【解决方案1】:
    <?php
    echo date('Y', strtotime('-1 month'));
    

    应该按预期工作。

    【讨论】:

      猜你喜欢
      • 2010-12-19
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      相关资源
      最近更新 更多