{"id":52733,"date":"2024-12-03T16:45:41","date_gmt":"2024-12-03T08:45:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52733\/"},"modified":"2024-12-03T16:45:41","modified_gmt":"2024-12-03T08:45:41","slug":"nodejs-%e4%b8%ad%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d-utc-%e6%97%b6%e9%97%b4%e6%88%b3%e8%87%aa%e5%8a%a8%e8%bd%ac%e5%8c%96%e4%b8%ba%e6%9c%ac%e5%9c%b0%e6%97%b6%e9%97%b4%e6%88%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52733\/","title":{"rendered":"NodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>NodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aNodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173228709367409a75613c3.jpg\" class=\"aligncenter\" title=\"NodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f\u63d2\u56fe\" alt=\"NodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 nodejs \u4e2d\u907f\u514d utc \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233<\/strong><\/p>\n<p>\u5728\u83b7\u53d6 utc \u65f6\u95f4\u5e76\u8f6c\u5316\u4e3a\u65f6\u95f4\u6233\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230 utc \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u95ee\u9898\u5e76\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u95ee\u9898\uff1a<\/p>\n<pre>const utc = new date().toutcstring();\nconsole.log(utc); \/\/ wed, 24 jan 2024 06:02:07 gmt\nconst utctimestamp = date.parse(utc);\nconsole.log(utctimestamp); \/\/ 1706076127000 (+8 \u65f6\u533a\u7684\u672c\u5730\u65f6\u95f4\u6233)<\/pre>\n<p>\u5982\u4f8b\u6240\u793a\uff0c\u83b7\u53d6\u7684 utc \u65f6\u95f4\u4e3a utc0 \u65f6\u533a\uff0c\u4f46\u8f6c\u5316\u4e3a\u65f6\u95f4\u6233\u540e\u5374\u53d8\u6210\u4e86\u672c\u5730\u65f6\u95f4\uff08+8 \u65f6\u533a\uff09\u7684\u65f6\u95f4\u6233\u3002<\/p>\n<p>\u89e3\u7b54\uff1a<\/p>\n<p>\u95ee\u9898\u7684\u539f\u56e0\u5728\u4e8e toutcstring() \u65b9\u6cd5\u8fd4\u56de\u7684\u65f6\u95f4\u5b57\u7b26\u4e32\u4e2d\u5305\u542b gmt \u6807\u5fd7\uff0c\u8868\u793a\u8be5\u65f6\u95f4\u5df2\u8f6c\u6362\u4e3a utc0 \u65f6\u533a\u3002\u56e0\u6b64\uff0cdate.parse() \u65b9\u6cd5\u5c06\u5176\u89e3\u6790\u4e3a utc0 \u65f6\u95f4\u6233\u3002<\/p>\n<p>\u8981\u907f\u514d\u81ea\u52a8\u8f6c\u5316\uff0c\u9700\u8981\u5728\u8f6c\u5316\u4e3a\u65f6\u95f4\u6233\u4e4b\u524d\u5220\u9664 gmt \u6807\u5fd7\u3002\u4ee5\u4e0b\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684\uff1a<\/p>\n<pre>const UTC = new Date().toUTCString();\nconsole.log(UTC); \/\/ Wed, 24 Jan 2024 06:02:07 GMT\nconst UTCtimestamp = Date.parse(UTC.split(' ').slice(0, 5).join(' '));\nconsole.log(UTCtimestamp); \/\/ 1706073447000 (UTC0 \u65f6\u95f4\u6233)<\/pre>\n<p>\u901a\u8fc7\u5220\u9664 gmt \u6807\u5fd7\u5e76\u53ea\u4fdd\u7559\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0cdate.parse() \u65b9\u6cd5\u5c06\u6b63\u786e\u5730\u5c06\u5b57\u7b26\u4e32\u89e3\u6790\u4e3a utc0 \u65f6\u95f4\u6233\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u5904\u7406\u9700\u8981\u4f7f\u7528\u672c\u5730\u65f6\u95f4\u6233\u7684\u573a\u666f\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u65f6\u533a\u504f\u79fb\u6765\u8c03\u6574\u65f6\u95f4\u6233\u4ee5\u5339\u914d\u7279\u5b9a\u65f6\u533a\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aNodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u63a2\u7d22 FR \u4f20\u5947\u7684\u60ca\u9669\u523a\u6fc0\uff1a\u72ec\u4e00\u65e0\u4e8c\u7684\u6f02\u6d41\u4f53\u9a8c\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>NodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f \u6536\u85cf \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aNodeJS \u4e2d\u5982\u4f55\u907f\u514d UTC \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 \u5982\u4f55\u5728 nodejs \u4e2d\u907f\u514d utc \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233 \u5728\u83b7\u53d6 utc \u65f6\u95f4\u5e76\u8f6c\u5316\u4e3a\u65f6\u95f4\u6233\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230 utc \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u5316\u4e3a\u672c\u5730\u65f6\u95f4\u6233\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u95ee\u9898\u5e76\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\u3002 \u95ee\u9898\uff1a const utc = new date().toutcstring(); console.log(utc); \/\/ wed, 24 jan 2024 06:02:07 gmt const utctimestamp = date.parse(utc); console.log(utctimestamp); \/\/ 1706076127000 (+8 \u65f6\u533a\u7684\u672c\u5730\u65f6\u95f4\u6233) \u5982\u4f8b\u6240\u793a\uff0c\u83b7\u53d6\u7684 utc \u65f6\u95f4\u4e3a utc0 \u65f6\u533a\uff0c\u4f46\u8f6c\u5316\u4e3a\u65f6\u95f4\u6233\u540e\u5374\u53d8\u6210\u4e86\u672c\u5730\u65f6\u95f4\uff08+8 \u65f6\u533a\uff09\u7684\u65f6\u95f4\u6233\u3002 \u89e3\u7b54\uff1a \u95ee\u9898\u7684\u539f\u56e0\u5728\u4e8e toutcstring() \u65b9\u6cd5\u8fd4\u56de\u7684\u65f6\u95f4\u5b57\u7b26\u4e32\u4e2d\u5305\u542b gmt \u6807\u5fd7\uff0c\u8868\u793a\u8be5\u65f6\u95f4\u5df2\u8f6c\u6362\u4e3a utc0 [&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-52733","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52733","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=52733"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52733\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}