开发者

php date format

I have a date in a variable like: 01-01-2009开发者_开发技巧 and need to change the format to Y-m-d. What should I use to do this conversion?


You can use the strtotime and date functions like this:

$str = '01-01-2009';
$date = date('Y-m-d', strtotime($str));

echo $date; //2009-01-01


To convert the date format from dd-mm-yyyy to yyyy-mm-dd in php,

<?php

$dt='01-01-2009';
$dt=date('Y-m-d',strtotime($dt));
echo $dt;

?>

The o/p will be, 2009-01-01

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜