将代码点火器的mysql时间戳转换为实际时间mm dd yyyy hh mm [复制]

This question already has an answer here:

Im trying to get the mysql timestamp to go to actual time. The PHP code im using though code igniter echos out the pub date for news articles but, its in this format yyyy-mm-dd hh:mm:ss I want it in MM/DD/YY HH:MM the code echos it out after running a query from a controller here is the code from the view <?php echo $row->pubdate; ?> pubdate is the column name from the MYSQL database. I've looked around stack overflow for an answer to this but I have not been able to find anything that works for my situation.

</div>

You could create a function which takes a MySQL formatted date and returns the format you want, something like this:

function nice_date($mysql_date)
{
    list($date,$time) = explode(" ",$mysql_date);
    list($year,$month,$day) = explode("-",$date);
    return $month.'/'.$day.'/'.$year.' '.$time;
}

Use explode to split the given date into $date and $time variables (using list to assign the variables), then split $date into year, month and day. Then simply return a string with the variables reordered.