开发者

PHP convert month

is there anyway to convert date month numeric to string.

e.g. for 1 convert to January, 2 => February, etc

i tried below

<?php ech开发者_如何学运维o date('F', strtotime($member['dob_month'])); ?>

didnt work out


<?php echo date("F",mktime(0,0,0,$member['dob_month'],1,0); ?>


$months = array(1 => 'January', 2 => 'February', ...);
echo $months[$member['dob_month']];

Given the value of $member['dob_month'] is an 1-based integer.


You can try to use PHP's DateTime class.

$date = DateTime::createFromFormat('n', $member['dob_month']);
echo $date->format('F');

Note: In createFromFormat, use 'm' if the month has leading zeros, 'n' if it doesn't.


Your problem is that date() needs a timestamp for it´s second parameter and strtotime($member['dob_month']) does not result in a meaningfull timestamp if $member['dob_month'] is a number from 1 to 12.

You can use something like:

date("F", mktime(0, 0, 0, $member['dob_month'], 1, 2010));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜