PHP converts monthly number to short month

I need to convert month-month to short month-name (i.e. 1 for January, February 2)

I know I can achieve this through Array, but is there any other way to do this?

Help evaluate.

Thanks.

+3
php
source share
2 answers

Yes there is. Use date / stftime in combination with mktime to create a timestamp for the desired month.

Strftime is cool because it will read the locale settings and display your written date parts in that particular language.

For example:

$time = mktime(0, 0, 0, $monthNumber); $name = strftime("%b", $time); 

Now let me say that you want your short month names in German to call setlocale before calling strftime:

 setlocale(LC_TIME, 'de_DE'); 
+12
source share
 for ($i=1;$i<=12;$i++) { echo date ("M", mktime(0,0,0,$i,1,0))."<br />"; } 

Without a for loop, for month 6:

  echo date ("M", mktime(0,0,0,6,1,0)); 
+3
source share

All Articles