开发者

PHP Date Format Issue

I have date in following form开发者_如何转开发at (Y-m-d) as 2010-11-24, need to convert it to

1) 24 Nov, 2010

2) 24_Nov_2010

Help appreciated, thanks.


$oDate = new DateTime('2010-11-24');
echo $oDate->format('d M, Y') . "\n";
echo $oDate->format('d_M_Y') . "\n";


  1. (d M, Y)
  2. (d_M_Y)

So, something like

date("d M, Y");

Will output todays date:

24 Nov, 2010

Edit: I may have read your question incorrectly. Can you please clarify if this is what you want? Or you wanted to convert the 24-11-2010 into the above formats?

If the latter if what you were seeking, you can simply utilise the strtotime function:

date("d M, Y", strtotime("2010-11-24"));


Most simple, you can use strtotime() to convert 2010-11-24 into date, and use date() to get seperate pieces(Y,m,D) and convert them to whatever format you want.

Please refer this link: http://php.net/manual/en/function.strtotime.php http://php.net/manual/en/function.date.php


$d1 = "2010-11-24";

echo date("d M, Y", strtotime($d1));   // 24 Nov, 2010
echo date("d_M_Y", strtotime($d1));    // 24_Nov_2010
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜