简体   繁体   English

如何在PHP中将月份编号转换为月份名称

[英]How to convert month number to month name in php

Is there a function in php wherein you can convert the number 12 to its equivalent in a month. PHP中是否有一个函数,您可以在一个月内将数字12转换为其等效值。 For example if the mysql database stores digits and not words for dates. 例如,如果mysql数据库存储的是数字而不是单词的日期。 how do you convert the number 12 into the word december? 您如何将数字12转换为12月这个词?

尝试此操作,并查看日期函数以获取更多答案:

date('F', mktime(0, 0, 0, 12))

您可以这样做:

echo date('F', mktime(0, 0, 0, 12));
strftime("%B", mktime(0, 0, 0, 12));

就像date()一样,除了如果您事先使用setlocale设置语言环境,它将为您进行本地化。

You could also do that directly in MySQL with 您也可以直接在MySQL中使用

SELECT MONTHNAME(STR_TO_DATE(12, '%m')); -- December

See http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date 参见http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date

date("F", mktime(0, 0, 0, 12, 1, 2000));

Use this code: 使用此代码:

echo date("F", mktime(0, 0, 0, $month, 1, 2010));

Where $month is your number from 1 to 12. 其中$ month是您的1到12之间的数字。

Read more at php functions reference: date 在php函数参考中了解更多信息: 日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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