如何在 PHP 中将数字转换为月份名称?


在 PHP 中将数字转换为月份名称,代码如下−

示例

 在线演示

<?php
   $date = "2019-11-11";
   echo "Displaying date...
";    echo "Date = $date";    $month_name = date("F", mktime(0, 0, 0, 11, 10));    echo "
Month = ".$month_name."
";    echo "
Displaying updated date...
";    echo date('Y-m-d', strtotime($date. ' + 20 days')); ?>

输出

这将生成以下输出−

Displaying date...
Date = 2019-11-11
Month = November
Displaying updated date...
2019-12-01

示例

现在让我们看另一个示例 −

 在线演示

<?php
   $date = "2019-11-11";
   echo "Displaying date...
";    echo "Date = $date";    $month_name = date("F", mktime(0, 0, 0, 11, 10));    echo "
Month = ".$month_name."
";    echo "
Displaying updated date...
";    echo date('Y-m-d', strtotime($date. ' + 20 days'));    $val = DateTime::createFromFormat('!m', 12);    $month_name2 = $val->format('F');    echo "
Month = ".$month_name2."
"; ?>

输出

这将生成以下输出 −

Displaying date...
Date = 2019-11-11
Month = November
Displaying updated date...
2019-12-01
Month = December

更新于:2019 年 12 月 26 日

2K+ 浏览

启动你的 职业生涯

完成课程即可获得认证

开始
广告