{"id":6759,"date":"2024-11-14T11:11:12","date_gmt":"2024-11-14T03:11:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6759\/"},"modified":"2024-11-14T11:11:12","modified_gmt":"2024-11-14T03:11:12","slug":"mysql-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%b0%86-int-%e6%97%b6%e9%97%b4%e6%88%b3%e8%bd%ac%e6%8d%a2%e4%b8%ba-timestamp%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6759\/","title":{"rendered":"MySQL \u4e2d\u5982\u4f55\u5c06 INT \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a TIMESTAMP\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172990387621002.jpg\" class=\"aligncenter\" title=\"MySQL \u4e2d\u5982\u4f55\u5c06 INT \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a TIMESTAMP\uff1f\u63d2\u56fe\" alt=\"MySQL \u4e2d\u5982\u4f55\u5c06 INT \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a TIMESTAMP\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4e2d\u5982\u4f55\u5c06 int \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a timestamp<\/strong><\/p>\n<p>\u5728 mysql \u8868\u4e2d\uff0c\u9700\u8981\u5c06 int \u7c7b\u578b\u7684\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a timestamp \u7c7b\u578b\u3002<\/p>\n<pre>\u8868\n&lt;table&gt;\n&lt;thead&gt;\n&lt;tr&gt;\n&lt;th&gt;id (bigint)&lt;\/th&gt;\n&lt;th&gt;created_at(int)&lt;\/th&gt;\n&lt;th&gt;created_time (timestamp)&lt;\/th&gt;\n&lt;\/tr&gt;\n&lt;\/thead&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td&gt;1&lt;\/td&gt;\n&lt;td&gt;1628075987&lt;\/td&gt;\n&lt;td&gt; &lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr&gt;\n&lt;td&gt;2&lt;\/td&gt;\n&lt;td&gt;1628075739&lt;\/td&gt;\n&lt;td&gt; &lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;\/tbody&gt;\n&lt;\/table&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>sql \u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u65e0\u9700\u901a\u8fc7\u7f16\u7a0b\u8bed\u8a00\u8bfb\u5199\uff0c\u53ef\u4ee5\u901a\u8fc7 sql \u76f4\u63a5\u8f6c\u6362\uff1a<\/p>\n<pre>update table_name set created_time = from_unixtime(created_at);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u6267\u884c\u4ee5\u4e0b\u67e5\u8be2\u5c06 int \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a timestamp\uff1a<\/p>\n<pre>select from_unixtime(1156219870);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c<\/strong><\/p>\n<pre>2006-09-20 04:04:30<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u751f\u6210\u7684 timestamp \u5217\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>created_time\n2021-08-04 17:06:27\n2021-08-04 17:02:19<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d\u5982\u4f55\u5c06 INT \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a TIMESTAMP\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2d\u5982\u4f55\u5c06 int \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a timestamp \u5728 mysql \u8868\u4e2d\uff0c\u9700\u8981\u5c06 int \u7c7b\u578b\u7684\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a timestamp \u7c7b\u578b\u3002 \u8868 &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;id (bigint)&lt;\/th&gt; &lt;th&gt;created_at(int)&lt;\/th&gt; &lt;th&gt;created_time (timestamp)&lt;\/th&gt; &lt;\/tr&gt; &lt;\/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;1&lt;\/td&gt; &lt;td&gt;1628075987&lt;\/td&gt; &lt;td&gt; &lt;\/td&gt; &lt;\/tr&gt; &lt;tr&gt; &lt;td&gt;2&lt;\/td&gt; &lt;td&gt;1628075739&lt;\/td&gt; &lt;td&gt; &lt;\/td&gt; &lt;\/tr&gt; &lt;\/tbody&gt; &lt;\/table&gt; \u767b\u5f55\u540e\u590d\u5236 sql \u89e3\u51b3\u65b9\u6848 \u65e0\u9700\u901a\u8fc7\u7f16\u7a0b\u8bed\u8a00\u8bfb\u5199\uff0c\u53ef\u4ee5\u901a\u8fc7 sql \u76f4\u63a5\u8f6c\u6362\uff1a update table_name set created_time = from_unixtime(created_at); \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b \u6267\u884c\u4ee5\u4e0b\u67e5\u8be2\u5c06 int \u65f6\u95f4\u6233\u8f6c\u6362\u4e3a timestamp\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6759","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6759"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6759\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}