从指定日期PHP获取年份 [英] Get the year from specified date php

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

问题描述

我的日期格式为 2068-06-15 。我想从日期开始,使用php函数。有人可以建议如何做到这一点。

I have a date in this format 2068-06-15. I want to get the year from the date, using php functions. Could someone please suggest how this could be done.

推荐答案

$date = DateTime::createFromFormat("Y-m-d", "2068-06-15");
echo $date->format("Y");

DateTime类在内部不使用unix时间戳,因此它可以处理1970年以前或2038年之后的日期。

The DateTime class does not use an unix timestamp internally, so it han handle dates before 1970 or after 2038.

这篇关于从指定日期PHP获取年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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