简体   繁体   中英

How do I convert numeric month number to name of month using PHP

I have a variable with a 2 digit month number. Is there a built in function that allows me to change it to the month name. I thought maybe the date() function would work, but that requires a full timestamp.

您可以将mktime与任意参数一起使用(月份除外),然后使用date格式化(这可能会为您提供一些区域设置)。

 date('M', mktime(0, 0, 0, $month, 1, 2000));

I use the following which is easier to code when needed many times

$month_names = array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

echo $month_names[3]; //prints March

Useful if you have a header or config file that's included on all your pages

Not to my knowledge.

You could use:

<?php
$monate = array(
   1=>"Januar",
   2=>"Februar",
   3=>"März",
   4=>"April",
   5=>"Mai",
   6=>"Juni",
   7=>"Juli",
   8=>"August",
   9=>"September",
   10=>"Oktober",
   11=>"November",
   12=>"Dezember");
?>

<?php
$monat = date("n");
??

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM