{"id":1496,"date":"2023-03-25T13:47:00","date_gmt":"2023-03-25T05:47:00","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1496"},"modified":"2023-04-28T20:28:43","modified_gmt":"2023-04-28T12:28:43","slug":"millisecond-processing-when-interacting-with-mysql-and-java","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/millisecond-processing-when-interacting-with-mysql-and-java\/","title":{"rendered":"MySQL\u4e0eJava\u4ea4\u4e92\u65f6\u6beb\u79d2\u5904\u7406"},"content":{"rendered":"<h2>\u95ee\u9898\u5206\u6790<\/h2>\n<p>MySQL\u5b57\u6bb5\u7c7b\u578b<code>datetime<\/code>\uff0c\u5b9e\u9645\u5b58\u50a8\u7684\u6570\u636e\u662f\uff1a<code>2020-09-08 17:01:16<\/code><\/p>\n<p>Java\u7684Date\u652f\u6301\u6beb\u79d2\uff0c\u6bd4\u5982\uff1a<code>2020-09-08 17:01:15.618<\/code>\uff0c\u901a\u8fc7<code>SimpleDateFormat<\/code>\u7b49\u683c\u5f0f\u5316\u540e\u7684\u65f6\u95f4\u683c\u5f0f\u4e3a\uff1a<code>2020-09-08 17:01:15<\/code><\/p>\n<p><!-- more --><\/p>\n<p>\u5bfc\u81f4MySQL\u8bfb\u53d6\u6570\u636e\u4e0eJava\u683c\u5f0f\u5316\u6570\u636e\u4e0d\u4e00\u81f4\u95ee\u9898<\/p>\n<p>\u539f\u56e0\uff1aMysql <code>dategtime<\/code>\u7c7b\u578b\u7684\u56db\u820d\u4e94\u5165\u95ee\u9898<\/p>\n<p>\u67e5\u770b<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.6\/en\/fractional-seconds.html\" title=\"MySQL 5.6 manual\">MySQL 5.6 manual<\/a>\u53d1\u73b0\uff0c5.6.4\u53ca\u4ee5\u4e0a\u7248\u672c\u7684MySQL Server\u7aef\u786e\u5b9e\u652f\u6301<code>fractional second part(fsp)<\/code>\uff0c\u4f46\u5982\u679cClient\u63d0\u4ea4\u8fc7\u6765\u7684\u5c0f\u6570\u4f4d\u6570\u8d85\u8fc7Server\u7aef\u5efa\u8868\u65f6\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u6570\uff0cMysql Server\u4f1a\u81ea\u52a8\u8fdb\u884c\u56db\u820d\u4e94\u5165\u7684\u622a\u65ad\uff0c\u6ca1\u6709\u4efb\u4f55\u8b66\u544a\u6216\u5f02\u5e38\u3002<\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>1\u3001\u5165\u5e93\u524d\u820d\u5f03\u6beb\u79d2\u90e8\u5206\u3002<br \/>\n2\u3001\u8bbe\u7f6eMysql <code>dategtime<\/code>\u7c7b\u578b\u7cbe\u5ea6<\/p>\n<h2>MySQL datetime\u503c\u6beb\u79d2\u56db\u820d\u4e94\u5165<\/h2>\n<h3>\u95ee\u9898<\/h3>\n<p>MySQL 5.6 \u7248\u672c\uff0c<code>datetime<\/code>\u5b57\u6bb5\u7c7b\u578b\u652f\u63016\u4f4d\u6beb\u79d2\u7ea7\u522b\uff0c\u63d2\u5165\u7684\u503c\u53ef\u80fd\u4f1a\u88ab\u56db\u820d\u4e94\u5165<\/p>\n<h3>\u5b9e\u4f8b1<\/h3>\n<pre><code class=\"language-sql\">CREATE TABLE appblog (\n`id` int(11) NOT NULL AUTO_INCREMENT,\n`gmt_create` datetime DEFAULT NULL,    #5.6 \u7248\u672c\u5b9a\u4e49\u683c\u5f0f\u4e3a datetime(6) \uff0c\u4fdd\u75596\u4f4d\u6beb\u79d2\u6570\u503c\u3002\u4e0d\u52a0\u8868\u793a\u4e0d\u4fdd\u7559\u6beb\u79d2\nPRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;<\/code><\/pre>\n<pre><code class=\"language-sql\">> insert into appblog select 1,&#039;2018-08-28 23:59:59.999&#039;;\n\n> select * from appblog;\n+----+---------------------+\n| id | gmt_create |\n+----+---------------------+\n| 1  | 2018-08-29 00:00:00 |    # \u5b57\u6bb5\u503c\u53d8\u4e86\uff01\uff01\uff01\n+----+---------------------+\n1 row in set (0.00 sec)<\/code><\/pre>\n<h3>\u5b9e\u4f8b2<\/h3>\n<pre><code class=\"language-sql\">CREATE TABLE appblog (\n`id` int(11) NOT NULL AUTO_INCREMENT,\n`gmt_create` datetime(3) DEFAULT NULL,\nPRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;<\/code><\/pre>\n<pre><code class=\"language-sql\">> insert into appblog select 1,&#039;2018-08-28 23:59:59.999&#039;;\n\n> insert into appblog select 2,&#039;2018-08-28 23:59:59.999999&#039;;\n\n> insert into appblog select 3,&#039;2018-08-28 23:59:59&#039;;\n\n> select * from appblog;\n\n+----+-------------------------+\n| id | gmt_create |\n+----+-------------------------+\n| 1  | 2018-08-28 23:59:59.999 |\n| 2  | 2018-08-29 00:00:00.000 |    # \u53c8\u53d8\u4e86\uff01\uff01\uff01\n| 3  | 2018-08-28 23:59:59.000 |\n+----+-------------------------+\n3 rows in set (0.00 sec)<\/code><\/pre>\n<pre><code class=\"language-sql\">> select * from appblog where gmt_create=&#039;2018-08-28 23:59:59&#039;;    #\u67e5\u8be2\u8fd8\u6709\u7cbe\u786e\u5ea6\u8981\u6c42\n+----+-------------------------+\n| id | gmt_create |\n+----+-------------------------+\n| 3 | 2018-08-28 23:59:59.000 |\n+----+-------------------------+<\/code><\/pre>\n<h3>\u603b\u7ed3<\/h3>\n<p>1\u3001MySQL 5.6 \u7248\u672c<code>datetime<\/code>\u6700\u591a\u652f\u63016\u4f4d\u6beb\u79d2\uff0c\u8bbe\u7f6e\u51e0\u4f4d\uff0c\u4e1a\u52a1\u5728\u5199\u5165\u65f6\u5019\uff0c\u5c31\u8981\u5199\u51e0\u4f4d\u3002\u4e0d\u80fd\u6bd4\u8bbe\u7f6e\u7684\u4f4d\u6570\u591a\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u56db\u820d\u4e94\u5165\u7684\u60c5\u51b5<br \/>\n2\u3001\u67e5\u8be2\u6709\u7cbe\u786e\u5ea6\u9650\u5236<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u5206\u6790 MySQL\u5b57\u6bb5\u7c7b\u578bdatetime\uff0c\u5b9e\u9645\u5b58\u50a8\u7684\u6570\u636e\u662f\uff1a2020-09-08 17:01:16 Jav [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[20],"class_list":["post-1496","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1496"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1496\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}