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

phpserver side programmingprogramming更新于 2025/5/8 18:37:17

要在 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

相关文章