Mysql 时间戳和 php date()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15515445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql timestamps and php date()
提问by user2177393
The mysql timestamp is in a standard format 2013-02-20 02:25:21, when I use date('H:i:s',$date) I get the same invalid output 18:33:33, how can I get the right output? hour:minute:seconds
mysql 时间戳是标准格式 2013-02-20 02:25:21,当我使用 date('H:i:s',$date) 我得到同样的无效输出 18:33:33,我怎么能得到正确的输出?时:分:秒
回答by Praveen kalal
use this date('Y-m-d H:i:s',strtotime($date));
用这个 date('Y-m-d H:i:s',strtotime($date));
回答by diEcho
Tip : try with MYSQL DATE_FORMATfunction
提示:尝试使用 MYSQLDATE_FORMAT函数
SELECT DATE_FORMAT('2013-02-20 02:25:21', '%H:%i:%s');
if you want to do it only with PHP then use strtotime
如果你只想用 PHP 来做,那么使用 strtotime
date('H:i:s',strtotime('2013-02-20 02:25:21'));
回答by Subedi Kishor
This might help you
这可能会帮助你
date('H:i:s',strtotime($date));
回答by Akash
Try this date('Y-m-d H:i:s',strtotime($date));
尝试这个 date('Y-m-d H:i:s',strtotime($date));

