将日期转换为月份名称&年 [英] Convert date to month name & year
本文介绍了将日期转换为月份名称&年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将日期转换为月份名称和年份.
I am trying to convert a date to month name and year.
$date = '2017-07-00';
$date = date('m/y', strtotime($date));
echo DATE_FORMAT($date, '%M %Y');
我希望输出类似
July, 2017
这是我得到的错误
Warning: date_format() expects parameter 1 to be DateTimeInterface, string given
推荐答案
不需要DATE_FORMAT()函数.
No Need of DATE_FORMAT() function.
示例1 :如果一天中使用00.然后,输出将为 2017年6月
Example-1: If 00 used in day. Then, output will be June, 2017
<?php
$date = '2017-07-00';
echo date('F, Y', strtotime($date)); //June, 2017
?>
示例2 :如果为01或一天中使用的有效日期.然后,输出将为 2017年7月
Example-2: If 01 or valid day used in day. Then, output will be July, 2017
<?php
$date = '2017-07-01';
echo date('F, Y', strtotime($date)); //July, 2017
?>
这篇关于将日期转换为月份名称&年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文