获取当年的最后一天作为日期 [英] Get the last day of the current year as date

查看:186
本文介绍了获取当年的最后一天作为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得当年的最后一天(12月31日)作为使用PHP的日期?

How can I get the last day (Dec 31) of the current year as a date using PHP?

我尝试过以下操作,但这不起作用:

I tried the following but this doesn't work:

$year = date('Y');
$yearEnd =  strtotime($year . '-12-31');

我需要的是当年的2014-12-31的日期。 p>

What I need is a date that looks like 2014-12-31 for the current year.

推荐答案

PHP strtotime()以当前日期/时间为基础所以它将使用这个当年),你需要 date()格式化:

PHP strtotime() uses the current date/time as a basis (so it will use this current year), and you need date() to format:

$yearEnd = date('Y-m-d', strtotime('Dec 31'));

//or

$yearEnd = date('Y-m-d', strtotime('12/31'));

这篇关于获取当年的最后一天作为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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