{"id":26955,"date":"2024-11-24T10:39:22","date_gmt":"2024-11-24T02:39:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26955\/"},"modified":"2024-11-24T10:39:22","modified_gmt":"2024-11-24T02:39:22","slug":"%e4%bd%bf%e7%94%a8prisma%e6%9f%a5%e8%af%a2mysql%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%8c%e6%97%b6%e9%97%b4%e5%b7%ae%e4%ba%868%e5%b0%8f%e6%97%b6%ef%bc%8c%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26955\/","title":{"rendered":"\u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\uff0c\u65f6\u95f4\u5dee\u4e868\u5c0f\u65f6\uff0c\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173113525912291.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\uff0c\u65f6\u95f4\u5dee\u4e868\u5c0f\u65f6\uff0c\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\uff0c\u65f6\u95f4\u5dee\u4e868\u5c0f\u65f6\uff0c\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Prisma\u64cd\u4f5cMySQL\u6570\u636e\u5e93\uff0c\u6570\u636e\u7684\u65f6\u95f4\u5c11\u4e868\u5c0f\u65f6\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\u65f6\uff0c\u53d1\u73b0\u521b\u5efa\u6570\u636e\u7684\u65f6\u95f4\u5c11\u4e868\u5c0f\u65f6\u3002\u8be5\u73b0\u8c61\u53ef\u80fd\u662f\u7531\u4e8e\u6570\u636e\u5e93\u65f6\u533a\u8bbe\u7f6e\u4e0e\u7a0b\u5e8f\u7684\u65f6\u533a\u5904\u7406\u65b9\u5f0f\u4e0d\u4e00\u81f4\u9020\u6210\u7684\u3002<\/p>\n<p><strong>\u539f\u56e0\u5206\u6790<\/strong><\/p>\n<p>MySQL\u6570\u636e\u5e93\u672c\u8eab\u5e76\u4e0d\u5b58\u50a8\u65f6\u533a\u4fe1\u606f\uff0c\u5b83\u4fdd\u5b58\u7684\u65f6\u95f4\u662fUTC\u65f6\u95f4\u3002\u800cPrisma\u4f1a\u6839\u636e\u7684\u65f6\u533a\u8bbe\u7f6e\u6765\u683c\u5f0f\u5316\u65f6\u95f4\u3002\u5982\u679c\u64cd\u4f5c\u7cfb\u7edf\u65f6\u533a\u8bbe\u7f6e\u4e3a\u4e1c\u516b\u533a\uff0c\u800c\u6570\u636e\u5e93\u8bbe\u7f6e\u4e3aUTC\u65f6\u95f4\uff0c\u5219Prisma\u4f1a\u5c06UTC\u65f6\u95f4\u51cf\u53bb8\u5c0f\u65f6\uff0c\u4ee5\u663e\u793a\u4e1c\u516b\u533a\u7684\u672c\u5730\u65f6\u95f4\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u7a0b\u5e8f\u4e2d\u660e\u786e\u6307\u5b9a\u65f6\u533a\uff0c\u5e76\u786e\u4fdd\u4e0e\u6570\u636e\u5e93\u65f6\u533a\u4e00\u81f4\u3002\u5efa\u8bae\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u8bbe\u7f6e\u6570\u636e\u5e93\u65f6\u533a\uff1a<\/strong>\u5728\u521b\u5efa\u6570\u636e\u5e93\u65f6\uff0c\u4f7f\u7528 SET TIMEZONE \u8bed\u53e5\u660e\u786e\u8bbe\u7f6e\u5176\u65f6\u533a\u4e3aUTC\u3002\u793a\u4f8b\uff1aSET TIMEZONE=&#8217;+00:00&#8242;.<\/li>\n<li> <strong>\u8bbe\u7f6ePrisma\u65f6\u533a\uff1a<\/strong>\u5728Prisma\u914d\u7f6e\u4e2d\uff0c\u4f7f\u7528 schema.prisma \u6587\u4ef6\u8bbe\u7f6eprisma\u7684\u65f6\u533a\u4e3aUTC \u3002\u793a\u4f8b\uff1a`datasource db {<br \/> provider = &#8220;&#8221;<br \/> url = &#8220;mysql:\/\/&#8230;&#8221;<br \/> # \u8bbe\u7f6e\u65f6\u533a\u4e3aUTC<br \/> # \u65f6\u533a\u4e0e\u60a8\u7684\u6570\u636e\u5e93\u65f6\u533a\u4e00\u81f4<br \/> # \u6307\u5357\uff1ahttps:\/\/www.prisma.io\/docs\/reference\/prisma-schema\/model-field-date-time#datetime-timezones<br \/> useDateTimeDefaultZone = &#8220;UTC&#8221;<br \/>}`<\/li>\n<li> <strong>\u5728\u7a0b\u5e8f\u4e2d\u8f6c\u6362\u65f6\u95f4\uff1a<\/strong>\u5728\u5c06\u65f6\u95f4\u6570\u636e\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e4b\u524d\uff0c\u5c06\u5176\u8f6c\u6362\u4e3aUTC\u65f6\u95f4\u3002\u5728\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u65f6\u95f4\u6570\u636e\u65f6\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u7a0b\u5e8f\u7684\u65f6\u533a\u3002<\/li>\n<\/ol>\n<p><strong>\u53c2\u8003<\/strong><\/p>\n<ul>\n<li>\u8003\u8651\u65f6\u533a\u4e86\u5417\uff1f\uff1ahttps:\/\/www.praetorian.com\/blog\/did-you-consider-time-zones<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\uff0c\u65f6\u95f4\u5dee\u4e868\u5c0f\u65f6\uff0c\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prisma\u64cd\u4f5cMySQL\u6570\u636e\u5e93\uff0c\u6570\u636e\u7684\u65f6\u95f4\u5c11\u4e868\u5c0f\u65f6\uff1f \u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\u65f6\uff0c\u53d1\u73b0\u521b\u5efa\u6570\u636e\u7684\u65f6\u95f4\u5c11\u4e868\u5c0f\u65f6\u3002\u8be5\u73b0\u8c61\u53ef\u80fd\u662f\u7531\u4e8e\u6570\u636e\u5e93\u65f6\u533a\u8bbe\u7f6e\u4e0e\u7a0b\u5e8f\u7684\u65f6\u533a\u5904\u7406\u65b9\u5f0f\u4e0d\u4e00\u81f4\u9020\u6210\u7684\u3002 \u539f\u56e0\u5206\u6790 MySQL\u6570\u636e\u5e93\u672c\u8eab\u5e76\u4e0d\u5b58\u50a8\u65f6\u533a\u4fe1\u606f\uff0c\u5b83\u4fdd\u5b58\u7684\u65f6\u95f4\u662fUTC\u65f6\u95f4\u3002\u800cPrisma\u4f1a\u6839\u636e\u7684\u65f6\u533a\u8bbe\u7f6e\u6765\u683c\u5f0f\u5316\u65f6\u95f4\u3002\u5982\u679c\u64cd\u4f5c\u7cfb\u7edf\u65f6\u533a\u8bbe\u7f6e\u4e3a\u4e1c\u516b\u533a\uff0c\u800c\u6570\u636e\u5e93\u8bbe\u7f6e\u4e3aUTC\u65f6\u95f4\uff0c\u5219Prisma\u4f1a\u5c06UTC\u65f6\u95f4\u51cf\u53bb8\u5c0f\u65f6\uff0c\u4ee5\u663e\u793a\u4e1c\u516b\u533a\u7684\u672c\u5730\u65f6\u95f4\u3002 \u89e3\u51b3\u65b9\u6848 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u7a0b\u5e8f\u4e2d\u660e\u786e\u6307\u5b9a\u65f6\u533a\uff0c\u5e76\u786e\u4fdd\u4e0e\u6570\u636e\u5e93\u65f6\u533a\u4e00\u81f4\u3002\u5efa\u8bae\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u8bbe\u7f6e\u6570\u636e\u5e93\u65f6\u533a\uff1a\u5728\u521b\u5efa\u6570\u636e\u5e93\u65f6\uff0c\u4f7f\u7528 SET TIMEZONE \u8bed\u53e5\u660e\u786e\u8bbe\u7f6e\u5176\u65f6\u533a\u4e3aUTC\u3002\u793a\u4f8b\uff1aSET TIMEZONE=&#8217;+00:00&#8242;. \u8bbe\u7f6ePrisma\u65f6\u533a\uff1a\u5728Prisma\u914d\u7f6e\u4e2d\uff0c\u4f7f\u7528 schema.prisma \u6587\u4ef6\u8bbe\u7f6eprisma\u7684\u65f6\u533a\u4e3aUTC \u3002\u793a\u4f8b\uff1a`datasource db { provider = &#8220;&#8221; url = &#8220;mysql:\/\/&#8230;&#8221; # \u8bbe\u7f6e\u65f6\u533a\u4e3aUTC # \u65f6\u533a\u4e0e\u60a8\u7684\u6570\u636e\u5e93\u65f6\u533a\u4e00\u81f4 # \u6307\u5357\uff1ahttps:\/\/www.prisma.io\/docs\/reference\/prisma-schema\/model-field-date-time#datetime-timezones useDateTimeDefaultZone = &#8220;UTC&#8221;}` \u5728\u7a0b\u5e8f\u4e2d\u8f6c\u6362\u65f6\u95f4\uff1a\u5728\u5c06\u65f6\u95f4\u6570\u636e\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e4b\u524d\uff0c\u5c06\u5176\u8f6c\u6362\u4e3aUTC\u65f6\u95f4\u3002\u5728\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u65f6\u95f4\u6570\u636e\u65f6\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u7a0b\u5e8f\u7684\u65f6\u533a\u3002 \u53c2\u8003 \u8003\u8651\u65f6\u533a\u4e86\u5417\uff1f\uff1ahttps:\/\/www.praetorian.com\/blog\/did-you-consider-time-zones \u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528Prisma\u67e5\u8be2MySQL\u6570\u636e\u5e93\uff0c\u65f6\u95f4\u5dee\u4e868\u5c0f\u65f6\uff0c\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-26955","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26955","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=26955"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26955\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}