{"id":207373,"date":"2025-07-08T09:12:04","date_gmt":"2025-07-08T01:12:04","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207373\/"},"modified":"2025-07-08T09:12:04","modified_gmt":"2025-07-08T01:12:04","slug":"%e8%a7%a3%e6%9e%90%e6%97%b6%e9%97%b4%e5%88%b0%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%b9%b6%e8%bf%94%e5%9b%9e","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207373\/","title":{"rendered":"\u89e3\u6790\u65f6\u95f4\u5230\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u89e3\u6790\u65f6\u95f4\u5230\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-21 23:36:36<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u89e3\u6790\u65f6\u95f4\u5230\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u5728 go \u4e2d\u505a\u4e00\u4e9b\u5728 java \u7b49\u8bed\u8a00\u4e2d\u975e\u5e38\u7b80\u5355\u7684\u4e8b\u60c5<\/p>\n<p>\u6211\u60f3\u5c06\u5f53\u524d\u65f6\u95f4\u89e3\u6790\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u5176\u89e3\u6790\u56de\u65f6\u95f4\u3002<\/p>\n<p>\u8fd9\u662f\u6211\u5c1d\u8bd5\u8fc7\u7684\u4ee3\u7801\uff0c\u4f46\u4ece\u8fd9\u91cc\u53ef\u4ee5\u770b\u51fa\uff0c\u5b83\u7ed9\u51fa\u4e86\u610f\u60f3\u4e0d\u5230\u7684\u7ed3\u679c\u3002 <\/p>\n<p>\u6211\u9762\u4e34\u4e24\u4e2a\u95ee\u9898<\/p>\n<ol>\n<li>time.now().string() \u7ed9\u51fa\u9519\u8bef\u7684\u65e5\u671f <\/li>\n<li>\u5982\u679c\u6211\u5c06\u65f6\u95f4\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 \u7136\u540e\u5c06\u5176\u6295\u5c04\u56de\u8fc7\u53bb\uff0c\u5b83\u4f1a\u7ed9\u51fa\u5b8c\u5168\u4e0d\u540c\u7684\u65e5\u671f\u3002<\/li>\n<\/ol>\n<p>\u6b63\u786e\uff08\u4e14\u7b80\u5355\uff09\u7684\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/p>\n<pre>p := fmt.Println\nstartStr := time.Now().String()   \/\/2009-11-10 23:00:00 +0000 UTC m=+0.000000001\np(startStr)\n\nstartTime, _ := time.Parse(\n    \"2009-11-10 23:00:00 +0000 UTC m=+0.000000001\",\n    startStr)\n\np(startTime)             \/\/0001-01-01 00:00:00 +0000 UTC<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p><code>time.now().string()<\/code> \u4ec5\u7528\u4e8e\u8c03\u8bd5\uff08\u8bf7\u53c2\u9605 <code>go doc<\/code>\uff09\u3002<\/p>\n<p>\u60a8\u5e94\u8be5\u4f7f\u7528 <code>time.format()<\/code>\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>p := fmt.println\n    now := time.now().format(time.rfc3339)\n    p(now)\n\n    parsed, _ := time.parse(time.rfc3339, now)\n    p(parsed.format(time.rfc3339))<\/pre>\n<p>\u4ea7\u751f\uff1a<\/p>\n<pre>2009-11-10t23:00:00z\n2009-11-10t23:00:00z<\/pre>\n<p>\u60a8\u5bf9 <code>time.now().string() \u7684\u5176\u4ed6\u62c5\u5fe7\u7ed9\u51fa\u4e86\u9519\u8bef\u7684 date<\/code> \u53ef\u80fd\u662f\u7531\u4e8e\u60a8\u8fd0\u884c\u4ee3\u7801\u7684\u4f4d\u7f6e\u6240\u81f4\u3002\u4f8b\u5982\u5982\u679c\u60a8\u5728\u201cthe go playgounrd\u201d\u4e2d\u8dd1\u6b65\uff0c\u90a3\u4e48\u65f6\u95f4\u5c06\u4e0d\u51c6\u786e\u3002\u60a8\u5e94\u8be5\u5728\u81ea\u5df1\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u5b83\uff0c\u5e76\u5047\u8bbe\u60a8\u7684\u8ba1\u7b97\u673a\u6709\u6b63\u786e\u7684\u65f6\u95f4\uff0c\u90a3\u4e48\u60a8\u5e94\u8be5\u6253\u5370\u51fa\u6b63\u786e\u7684\u65f6\u95f4\u3002<\/p>\n<p>\u4e0e\u5176\u4ed6\u4e00\u4e9b\u8bed\u8a00\u4e0d\u540c\uff0cgo \u5e76\u4e0d\u5c06 string() \u89c6\u4e3a\u4e8b\u5b9e\u4e0a\u7684\u65f6\u95f4\u5c01\u9001\u5904\u7406\u65b9\u6cd5\u2014\u2014\u76f8\u53cd\uff0c\u5b83\u53ea\u662f\u4e3a\u4e86\u8c03\u8bd5\u76ee\u7684\u800c\u6253\u5370\u51fa\u503c\u3002\u5982\u679c\u60a8\u4f7f\u7528\u6b63\u786e\u7684\u683c\u5f0f\u5b57\u7b26\u4e32\uff0c\u60a8\u53ef\u4ee5\u4ece\u8be5\u683c\u5f0f\u89e3\u6790\u56de\u65f6\u95f4\uff1b\u4f46\u662f\uff0c\u6b63\u786e\u7684\u683c\u5f0f\u5b57\u7b26\u4e32\u5fc5\u987b\u662f <code>mon jan 2 15:04:05 mst 2006<\/code> \u7684\u51c6\u786e\u65f6\u95f4\uff0c\u800c\u4e0d\u662f\u4efb\u4f55\u65f6\u95f4\uff1b\u4f46\u662f string() \u6253\u5370\u51fa\u7684\u683c\u5f0f\u4e0d\u4f1a\u88ab time \u5305\u4e2d\u7684\u5e38\u91cf\u6355\u83b7\uff0c\u56e0\u6b64\u53ef\u80fd\u4e0d\u503c\u5f97\u8fd9\u6837\u505a\u3002<\/p>\n<p>\u4f46\u662f\uff0cmarshaltext \u548c unmarshaltext \u65b9\u6cd5\u53ef\u80fd\u4f1a\u66f4\u597d\u5730\u6355\u83b7\u60a8\u5c1d\u8bd5\u6267\u884c\u7684\u64cd\u4f5c\uff1a<\/p>\n<pre>startStr, _ := time.Now().MarshalText()\nfmt.Println(string(startStr)) \/\/ 2009-11-10T23:00:00Z\n\nstartTime := new(time.Time)\nstartTime.UnmarshalText(startStr)\n\nfmt.Println(startTime) \/\/ 2009-11-10 23:00:00 +0000 UTC<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u89e3\u6790\u65f6\u95f4\u5230\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de\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~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03Golang\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207373","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207373"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207373\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}