mysql 时间
Posted RainDream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 时间相关的知识,希望对你有一定的参考价值。
显示当前时间:
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2016-12-27 23:42:25 | +---------------------+ 1 row in set (0.00 sec) mysql> SELECT CURRENT_TIMESTAMP; +---------------------+ | CURRENT_TIMESTAMP | +---------------------+ | 2016-12-27 23:41:08 | +---------------------+ 1 row in set (0.00 sec)
以秒形式显示当前时间:
mysql> select UNIX_TIMESTAMP(); +------------------+ | UNIX_TIMESTAMP() | +------------------+ | 1482853439 | +------------------+ 1 row in set (0.00 sec)
精确到毫秒:
mysql> SELECT ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000); +------------------------------------------+ | ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) | +------------------------------------------+ | 1482853561290 | +------------------------------------------+ 1 row in set (0.02 sec)
mysql在5.6.4版本之前会将秒之后的时间截取掉,也就是最高精度只到秒。5.6.4及之后的版本支持到微秒(2010-12-10 14:12:09.019473,小数点后6位)。不过创建表时需要指定精度,指定小数点后存储几位:
CREATE TABLE t1 (t TIME(3), dt DATETIME(6));
例如:
mysql> CREATE TABLE fractest( c1 TIME(2), c2 DATETIME(2), c3 TIMESTAMP(2) ); Query OK, 0 rows affected (0.61 sec) mysql> INSERT INTO fractest VALUES (‘17:51:04.777‘, ‘2016-10-10 17:51:04.777‘, ‘2016-10-10 17:51:04.777‘); Query OK, 1 row affected (0.05 sec) mysql> SELECT * FROM fractest; +-------------+------------------------+------------------------+ | c1 | c2 | c3 | +-------------+------------------------+------------------------+ | 17:51:04.78 | 2016-10-10 17:51:04.78 | 2016-10-10 17:51:04.78 | +-------------+------------------------+------------------------+ 1 row in set (0.00 sec)
以上是关于mysql 时间的主要内容,如果未能解决你的问题,请参考以下文章
使用 json rereiver php mysql 在片段中填充列表视图
连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段
关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段
修改MySQL密码报错“ERROR 1819 (HY000): Your password does not satisfy the current policy requirements“(代码片段