MySQL 时间戳格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20020259/
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 Timestamp format
提问by Devel
I have exported my database to a CSV file and the timestamp now liiks like this:
我已将我的数据库导出到 CSV 文件,现在时间戳如下所示:
1384204028
1384204028
How can I convert it to the typical format, for example 2013-01-19 03:14:07
?
例如,如何将其转换为典型格式2013-01-19 03:14:07
?
回答by John Conde
Use FROM_UNIXTIME()
SELECT FROM_UNIXTIME(1384204028);
or (equivalent but with parameter to control the format):
或(等效但带有控制格式的参数):
SELECT FROM_UNIXTIME(1384204028, '%Y-%m-%d %H:%i:%s');
回答by Dmitry Seleznev
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')
回答by and-bri
if you just want to add a line in your DB-table, where you have a field as TIMESTAMP, you don't need to call a function. You just can pas a string, sql will do the rest.
如果您只想在 DB 表中添加一行,其中有一个字段作为 TIMESTAMP,则不需要调用函数。您只需传递一个字符串,sql 将完成其余的工作。
INSERT INTO `DB_TABLE`(`id`, `message`, `next_time`) VALUES (12, 'hallo world', '20180601151343')
and will even work like this:
甚至会像这样工作:
INSERT INTO `DB_TABLE`(`id`, `message`, `next_time`) VALUES (12, 'hallo world', '2018-06-01 15:13:43')