【问题标题】:How to get the year number with PHP? [duplicate]如何使用 PHP 获取年份? [复制]
【发布时间】:2010-11-24 06:28:04
【问题描述】:

可能重复:
How do I use PHP to get the current year?

2009这一年, 明年2010年。

【问题讨论】:

标签: php date


【解决方案1】:

查看函数 date() 和 strtotime():

echo date('Y');
echo date('Y', strtotime('+1 year'));

【讨论】:

    【解决方案2】:

    您可以使用日期函数提取日期的一部分:

    $year = date("Y"); // get the year part of the current date
    $nextYear = $year + 1;
    

    运行 sn-p here

    【讨论】:

      【解决方案3】:
      <?php
      $date="2010-04-30";
      $y = date('Y',strtotime($date));
      echo $y; 
      ?>
      

      【讨论】:

        【解决方案4】:

        使用getdate()函数

        【讨论】:

          【解决方案5】:

          ...strftime('%Y') 也这样做了

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2023-03-16
            • 2012-02-16
            • 2022-11-27
            • 2020-03-15
            • 1970-01-01
            • 2021-11-16
            • 1970-01-01
            • 2014-06-22
            相关资源
            最近更新 更多