去年的开始和结束日期如何? [英] How do I get last year's start and end date?

查看:87
本文介绍了去年的开始和结束日期如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PHP代码获取去年的开始和结束日期?有可能吗?

How can I get last year's start and end date using PHP code? Is it possible?

推荐答案

第一天永远是1月1日,最后一天总是12月31日。你真的只是改变附加的年份。根据你想要的日期格式,你有几种可能性...

The first day is always January 1, the last day is always December 31. You're really only changing the year attached to it. Depending on how you want the date formatted, you have a couple possibilities...


  1. 如果你只想显示物理日期:

  1. If you just want to display the physical date:

$year = date('Y') - 1; // Get current year and subtract 1
$start = "January 1st, {$year}";
$end = "December 31st, {$year}";


  • 如果您需要两个日期的时间戳:

  • If you need the timestamp for both those dates:

    $year = date('Y') - 1; // Get current year and subtract 1
    $start = mktime(0, 0, 0, 1, 1, $year);
    $end = mktime(0, 0, 0, 12, 31, $year);
    


  • 很简单的东西。您也可以手动指定哪一年。前提是一样的。

    Very simple stuff. You can manually specify which year if you wanted too. The premise is the same.

    这篇关于去年的开始和结束日期如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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