I need to convert month-number to short month-name (i.e., 1 for Jan, 2 for Feb)
I know that I can achieve this via Array, but is there any other way to do it?
Help appreciated.
Thanks.
Yes there is. Use date/stftime in combination with mktime to create a timestamp within the desired month.
Strftime is cool because it will read the locale setting, and output your written date parts in that specific language.
For example:
$time = mktime(0, 0, 0, $monthNumber);
$name = strftime("%b", $time);
Now lets say you want your short month names in german language you call setlocale before calling strftime:
setlocale(LC_TIME, 'de_DE');
for ($i=1;$i<=12;$i++) {
echo date ("M", mktime(0,0,0,$i,1,0))."<br />";
}
Without the for
loop, for month 6:
echo date ("M", mktime(0,0,0,6,1,0));
精彩评论