{"id":53332,"date":"2024-12-03T13:47:38","date_gmt":"2024-12-03T05:47:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53332\/"},"modified":"2024-12-03T13:47:38","modified_gmt":"2024-12-03T05:47:38","slug":"koa-node-js-%e4%b8%ad%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a1%ae%e8%8e%b7%e5%8f%96-utc-%e6%97%b6%e9%97%b4%e6%88%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53332\/","title":{"rendered":"Koa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Koa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aKoa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/1732858969674954593441f.jpg\" class=\"aligncenter\" title=\"Koa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f\u63d2\u56fe\" alt=\"Koa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>nodejs \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 utc \u65f6\u95f4\u6233\uff1f<\/strong><\/p>\n<p>\u5728 koa\/nodejs \u4e2d\uff0c\u83b7\u53d6 utc \u65f6\u95f4\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u7136\u800c\uff0c\u4f7f\u7528 date.parse(utc) \u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230 utc \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u95f4\u6233\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u95ee\u9898\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ctoutcstring() \u8fd4\u56de\u7684 utc \u65f6\u95f4\u5b57\u7b26\u4e32\u5305\u542b gmt \u6807\u8bc6\uff0c\u8868\u793a\u683c\u6797\u5c3c\u6cbb\u6807\u51c6\u65f6\u95f4\u3002\u6b64\u6807\u8bc6\u901a\u5e38\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u533a\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u65f6\u95f4\u6233\u53d1\u751f\u504f\u79fb\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u83b7\u5f97\u771f\u5b9e\u7684 utc \u65f6\u95f4\u6233\uff0c\u800c\u4e0d\u53d7\u672c\u5730\u65f6\u533a\u7684\u5e72\u6270\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u4f7f\u7528 valueof() \u65b9\u6cd5\uff1a<\/strong><\/li>\n<\/ol>\n<p>\u8be5\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u4e0e\u7ed9\u5b9a\u65e5\u671f\u5173\u8054\u7684 utc \u65f6\u95f4\u6233\uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09\u3002<\/p>\n<pre>const utctimestamp = new date().valueof();<\/pre>\n<ol>\n<li><strong>\u4f7f\u7528 moment.js \u5e93\uff1a<\/strong><\/li>\n<\/ol>\n<p>moment.js \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u65e5\u671f\u4e0e\u65f6\u95f4\u64cd\u4f5c\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u65b9\u6cd5\u6765\u83b7\u53d6 utc \u65f6\u95f4\u6233\uff1a<\/p>\n<pre>const moment = require('moment');\nconst UTCtimestamp = moment().utc().valueOf();<\/pre>\n<p><strong>\u5efa\u8bae\uff1a<\/strong><\/p>\n<p>\u59cb\u7ec8\u4f7f\u7528 valueof() \u65b9\u6cd5\u6216 moment.js \u5e93\u6765\u83b7\u53d6 utc \u65f6\u95f4\u6233\uff0c\u4ee5\u907f\u514d\u81ea\u52a8\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u533a\u3002\u6b64\u5916\uff0c\u5728\u5904\u7406 utc \u65f6\u95f4\u65f6\uff0c\u8bf7\u6ce8\u610f\u65f6\u533a\u5dee\u5f02\uff0c\u5e76\u5728\u5fc5\u8981\u65f6\u8fdb\u884c\u76f8\u5e94\u7684\u8c03\u6574\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/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   Go\u8bed\u8a00\u4e2d\u4f7f\u7528map[string]interface{}\u6709\u54ea\u4e9b\u6f5c\u5728\u95ee\u9898\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Koa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f \u6536\u85cf \u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aKoa\/Node.js \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 UTC \u65f6\u95f4\u6233\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 nodejs \u4e2d\u5982\u4f55\u6b63\u786e\u83b7\u53d6 utc \u65f6\u95f4\u6233\uff1f \u5728 koa\/nodejs \u4e2d\uff0c\u83b7\u53d6 utc \u65f6\u95f4\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u7136\u800c\uff0c\u4f7f\u7528 date.parse(utc) \u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230 utc \u65f6\u95f4\u6233\u81ea\u52a8\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u95f4\u6233\u7684\u95ee\u9898\u3002 \u95ee\u9898\u539f\u56e0\uff1a \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ctoutcstring() \u8fd4\u56de\u7684 utc \u65f6\u95f4\u5b57\u7b26\u4e32\u5305\u542b gmt \u6807\u8bc6\uff0c\u8868\u793a\u683c\u6797\u5c3c\u6cbb\u6807\u51c6\u65f6\u95f4\u3002\u6b64\u6807\u8bc6\u901a\u5e38\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u533a\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u65f6\u95f4\u6233\u53d1\u751f\u504f\u79fb\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u4e3a\u4e86\u83b7\u5f97\u771f\u5b9e\u7684 utc \u65f6\u95f4\u6233\uff0c\u800c\u4e0d\u53d7\u672c\u5730\u65f6\u533a\u7684\u5e72\u6270\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u4f7f\u7528 valueof() \u65b9\u6cd5\uff1a \u8be5\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u4e0e\u7ed9\u5b9a\u65e5\u671f\u5173\u8054\u7684 utc \u65f6\u95f4\u6233\uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09\u3002 const utctimestamp = new date().valueof(); \u4f7f\u7528 moment.js \u5e93\uff1a moment.js \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u65e5\u671f\u4e0e\u65f6\u95f4\u64cd\u4f5c\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u65b9\u6cd5\u6765\u83b7\u53d6 utc \u65f6\u95f4\u6233\uff1a const moment = require(&#8216;moment&#8217;); [&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-53332","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53332","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=53332"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53332\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}