如何将月份数转换为月份短名称?

时间:2012-01-01 06:01:30

标签: php date strtotime

例如我的月号是(3 = 3月)或(2 = 2月),我尝试了以下代码,但它不起作用。如何解决?

$month = 2; 
echo date('M', strtotime($month));

演示: http://codepad.viper-7.com/ZKctjg

1 个答案:

答案 0 :(得分:3)

根据您的代码:

$month = 2; 
echo date('M', strtotime('2012-' . $month . '-01'));

strtotime()接受日期而不仅仅是月份

相关问题