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.

</div>
  • 写回答

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 运筹学排序问题中的在线排序
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧