douwen3127 2015-09-05 20:40
浏览 42

将代码点火器的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.

  • 写回答

1条回答 默认 最新

  • dqm83011 2015-09-05 20:44

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 c++图Djikstra算法求最短路径
    • ¥15 Linux操作系统中的,管道通信问题
    • ¥15 请问这张multisim图的原理是什么,这是一个交通灯,是课程要求,明天要进行解析,但是我们组没一个人会,所以急要,今天要
    • ¥15 ansible tower 卡住
    • ¥15 等间距平面螺旋天线方程式
    • ¥15 通过链接访问,显示514或不是私密连接
    • ¥100 系统自动弹窗,键盘一接上就会
    • ¥50 股票交易系统设计(sql语言)
    • ¥15 调制识别中这几个数据集的文献分别是什么?
    • ¥15 使用c语言对日志文件处理