将日期转换为月份名称&年

问题描述:

我正在尝试将日期转换为月份名称和年份.

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
?>