{"id":6728,"date":"2024-11-14T11:37:14","date_gmt":"2024-11-14T03:37:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6728\/"},"modified":"2024-11-14T11:37:14","modified_gmt":"2024-11-14T03:37:14","slug":"sequelize-%e9%bb%98%e8%ae%a4-createdat-%e6%97%b6%e9%97%b4%e4%b8%8e%e5%ae%9e%e9%99%85%e6%97%b6%e9%97%b4%e4%b8%8d%e7%ac%a6%ef%bc%9f%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6728\/","title":{"rendered":"Sequelize \u9ed8\u8ba4 createdAt \u65f6\u95f4\u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u7b26\uff1f\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172983440163738.jpg\" class=\"aligncenter\" title=\"Sequelize \u9ed8\u8ba4 createdAt \u65f6\u95f4\u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u7b26\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Sequelize \u9ed8\u8ba4 createdAt \u65f6\u95f4\u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u7b26\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>sequelize\u7684\u9ed8\u8ba4createdat\u65f6\u95f4\u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u7b26\u7684\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<p>\u4f7f\u7528 sequelize \u521b\u5efa  \u8868\u65f6\uff0csequelize \u4f1a\u81ea\u52a8\u521b\u5efa <strong>createdat<\/strong> \u548c <strong>updatedat<\/strong> \u5b57\u6bb5\uff0c\u5e76\u63d0\u4f9b\u9ed8\u8ba4\u65f6\u95f4\u503c\u3002\u7136\u800c\uff0c\u4e00\u4e9b\u7528\u6237\u53d1\u73b0\uff0csequelize \u751f\u6210\u7684\u9ed8\u8ba4\u65f6\u95f4\u503c\u4e0e\u5b9e\u9645\u65f6\u95f4\u76f8\u5dee\u8f83\u5927\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u8bf7\u5728 sequelize \u521d\u59cb\u5316\u65f6\u6307\u5b9a <strong>timezone<\/strong> \u548c <strong>useutc<\/strong> \u9009\u9879\uff1a<\/p>\n<pre>const sequelize = new Sequelize('database', 'username', 'password', {\n  host: 'localhost',\n  dialect: 'mssql',\n  timezone: '+8:00',\n  dialectOptions: {\n    useUTC: false\n  }\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>timezone:<\/strong> \u6307\u5b9a\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u65f6\u533a\uff0c\u5728\u672c\u4f8b\u4e2d\u5047\u8bbe\u4e3a utc+8\u3002<\/li>\n<li> <strong>useutc:<\/strong> \u8bbe\u7f6e\u4e3a <strong>false<\/strong> \u4ee5\u7981\u7528 sequelize \u4f7f\u7528 utc \u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e9b\u9009\u9879\uff0csequelize \u5c06\u4f7f\u7528\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u65f6\u533a\u751f\u6210 <strong>createdat<\/strong> \u548c <strong>updatedat<\/strong> \u7684\u503c\uff0c\u4ece\u800c\u786e\u4fdd\u8fd9\u4e9b\u503c\u4e0e\u5b9e\u9645\u65f6\u95f4\u51c6\u786e\u5bf9\u9f50\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSequelize \u9ed8\u8ba4 createdAt \u65f6\u95f4\u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u7b26\uff1f\u5982\u4f55\u89e3\u51b3\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>sequelize\u7684\u9ed8\u8ba4createdat\u65f6\u95f4\u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u7b26\u7684\u89e3\u51b3\u65b9\u6cd5 \u4f7f\u7528 sequelize \u521b\u5efa \u8868\u65f6\uff0csequelize \u4f1a\u81ea\u52a8\u521b\u5efa createdat \u548c updatedat \u5b57\u6bb5\uff0c\u5e76\u63d0\u4f9b\u9ed8\u8ba4\u65f6\u95f4\u503c\u3002\u7136\u800c\uff0c\u4e00\u4e9b\u7528\u6237\u53d1\u73b0\uff0csequelize \u751f\u6210\u7684\u9ed8\u8ba4\u65f6\u95f4\u503c\u4e0e\u5b9e\u9645\u65f6\u95f4\u76f8\u5dee\u8f83\u5927\u3002 \u8981\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u8bf7\u5728 sequelize \u521d\u59cb\u5316\u65f6\u6307\u5b9a timezone \u548c useutc \u9009\u9879\uff1a const sequelize = new Sequelize(&#8216;database&#8217;, &#8216;username&#8217;, &#8216;password&#8217;, { host: &#8216;localhost&#8217;, dialect: &#8216;mssql&#8217;, timezone: &#8216;+8:00&#8217;, dialectOptions: { useUTC: false } }); \u767b\u5f55\u540e\u590d\u5236 timezone: \u6307\u5b9a\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u65f6\u533a\uff0c\u5728\u672c\u4f8b\u4e2d\u5047\u8bbe\u4e3a utc+8\u3002 useutc: \u8bbe\u7f6e\u4e3a false \u4ee5\u7981\u7528 sequelize \u4f7f\u7528 utc \u65f6\u95f4\u3002 \u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e9b\u9009\u9879\uff0csequelize \u5c06\u4f7f\u7528\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u65f6\u533a\u751f\u6210 createdat \u548c updatedat [&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-6728","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6728","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=6728"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6728\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}