{"id":42995,"date":"2024-12-01T09:54:14","date_gmt":"2024-12-01T01:54:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42995\/"},"modified":"2024-12-01T09:54:14","modified_gmt":"2024-12-01T01:54:14","slug":"go-%e5%b0%8f%e6%97%b6%e8%bd%ac%e6%8d%a2%e7%ae%97%e6%b3%95%e6%9c%aa%e6%ad%a3%e7%a1%ae%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42995\/","title":{"rendered":"Go \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362"},"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>Go \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362<\/span><\/p>\n<h1>Go \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-28 10:03:28<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662fGolang\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aGo \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u9047\u5230\u4e86\u4e00\u4e2a hackerrank \u6311\u6218\uff0c\u6211\u5e94\u8be5\u6784\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u5c06\u7ed9\u5b9a\u65f6\u95f4\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u4ece 12 \u5c0f\u65f6\u683c\u5f0f\u8f6c\u6362\u4e3a 24 \u5c0f\u65f6\u683c\u5f0f\u3002<\/p>\n<p>\u6211\u8bbe\u6cd5\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u505a\u5230\u4e86\u8fd9\u4e00\u70b9\uff0c\u4f46\u6b63\u5982\u60a8\u6240\u6ce8\u610f\u5230\u7684\uff0c\u665a\u4e0a 9 \u70b9\u6709\u4e00\u4e2a\u7279\u6b8a\u60c5\u51b5\u3002\u6bcf\u5f53\u6211\u8f93\u5165\u4ee5 09 \u5f00\u5934\u7684\u4e00\u4e2a\u5c0f\u65f6\uff08\u53ea\u6709\u8fd9\u4e2a\u8be5\u6b7b\u7684\uff09\u65f6\uff0c\u5b83\u4f1a\u5c06 09 \u8f6c\u6362\u4e3a 12\u3002\u6240\u4ee5\u6211\u5fc5\u987b\u521b\u5efa\u4e00\u4e2a\u7279\u5b9a\u7684\u6848\u4f8b\u6765\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\uff0c\u8fd9\u5f88\u6709\u6548\uff0c\u4f46\u6211\u60f3\u4e86\u89e3\u4e3a\u4ec0\u4e48\u5b83\u53d1\u751f\u4e86\u3002\u4f60\u77e5\u9053\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u5417\uff1f<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n    \"strings\"\n)\n\ntype Conversion struct {\n    conversion string\n}\n\nfunc timeConversion(s string) string {\n    var conversion Conversion\n    firstValue := fmt.Sprintf(\"%s%s\", string(s[0]), string(s[1]))\n    secondValue := fmt.Sprintf(\"%s%s\", string(s[3]), string(s[4]))\n    firstValueNumber, _ := strconv.ParseInt(firstValue, 0, 16)\n\n    fmt.Print()\n\n    if strings.Contains(s, \"A\") {\n        if firstValue == \"12\" {\n            conversion.conversion = fmt.Sprintf(\"%s:%s:%s%s\", \"00\", secondValue, string(s[len(s)-4]), string(s[len(s)-3]))\n        } else {\n            conversion.conversion = fmt.Sprintf(\"%s:%s:%s%s\", firstValue, secondValue, string(s[len(s)-4]), string(s[len(s)-3]))\n        }\n    } else if strings.Contains(s, \"P\") {\n        if firstValue == \"12\" {\n            conversion.conversion = fmt.Sprintf(\"%s:%s:%s%s\", \"12\", secondValue, string(s[len(s)-4]), string(s[len(s)-3]))\n        } else if firstValue == \"09\" {\n            conversion.conversion = fmt.Sprintf(\"%s:%s:%s%s\", \"21\", secondValue, string(s[len(s)-4]), string(s[len(s)-3]))\n        } else {\n            conversion.conversion = fmt.Sprintf(\"%d:%s:%s%s\", firstValueNumber+12, secondValue, string(s[len(s)-4]), string(s[len(s)-3]))\n        }\n    }\n\n    return conversion.conversion\n}\n\nfunc main() {\n    fmt.Print(timeConversion(\"09:08:23PM\"))\n}<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u5982\u679c\u60a8\u5728\u5b57\u7b26\u4e32\u5230 int \u8f6c\u6362\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u9519\u8bef\uff0c\u60a8\u4f1a\u6ce8\u610f\u5230\u5bf9\u4e8e\u503c <code>&gt;7<\/code>\uff0c\u8f6c\u6362\u5931\u8d25<\/p>\n<pre>firstValueNumber, err := strconv.ParseInt(firstValue, 0, 64)\nif err != nil {\n     fmt.Printf(\"%s\", err.Error())\n}\n\/\/ \"08\" results in invalid syntaxfirstValueNumber being printed<\/pre>\n<p>\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u662f\u56e0\u4e3a\u60a8\u4f20\u9012 0 \u4f5c\u4e3a\u57fa\u6570\uff0c\u544a\u8bc9 <code>parseint<\/code> \u4ece\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u63a8\u65ad\u57fa\u6570\u3002\u524d\u5bfc <code>'0'<\/code> \u610f\u5473\u7740\u516b\u8fdb\u5236\u57fa\u6570\uff0c\u56e0\u6b64\u5927\u4e8e 7 \u7684\u6570\u5b57\u5c06\u65e0\u6548\u3002\u76f8\u53cd\uff0c\u4f20\u9012 10 \u5c31\u4e0d\u9700\u8981\u7279\u6b8a\u5904\u7406\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\u4e8eGolang\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","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; Go \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362 Go \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362 \u6765\u6e90\uff1astackoverflow 2024-04-28 10:03:28 0\u6d4f\u89c8 \u6536\u85cf \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662fGolang\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aGo \u5c0f\u65f6\u8f6c\u6362\u7b97\u6cd5\u672a\u6b63\u786e\u8f6c\u6362\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u9047\u5230\u4e86\u4e00\u4e2a hackerrank \u6311\u6218\uff0c\u6211\u5e94\u8be5\u6784\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u5c06\u7ed9\u5b9a\u65f6\u95f4\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u4ece 12 \u5c0f\u65f6\u683c\u5f0f\u8f6c\u6362\u4e3a 24 \u5c0f\u65f6\u683c\u5f0f\u3002 \u6211\u8bbe\u6cd5\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u505a\u5230\u4e86\u8fd9\u4e00\u70b9\uff0c\u4f46\u6b63\u5982\u60a8\u6240\u6ce8\u610f\u5230\u7684\uff0c\u665a\u4e0a 9 \u70b9\u6709\u4e00\u4e2a\u7279\u6b8a\u60c5\u51b5\u3002\u6bcf\u5f53\u6211\u8f93\u5165\u4ee5 09 \u5f00\u5934\u7684\u4e00\u4e2a\u5c0f\u65f6\uff08\u53ea\u6709\u8fd9\u4e2a\u8be5\u6b7b\u7684\uff09\u65f6\uff0c\u5b83\u4f1a\u5c06 09 \u8f6c\u6362\u4e3a 12\u3002\u6240\u4ee5\u6211\u5fc5\u987b\u521b\u5efa\u4e00\u4e2a\u7279\u5b9a\u7684\u6848\u4f8b\u6765\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\uff0c\u8fd9\u5f88\u6709\u6548\uff0c\u4f46\u6211\u60f3\u4e86\u89e3\u4e3a\u4ec0\u4e48\u5b83\u53d1\u751f\u4e86\u3002\u4f60\u77e5\u9053\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u5417\uff1f package main import ( &#8220;fmt&#8221; &#8220;strconv&#8221; &#8220;strings&#8221; ) type Conversion struct { conversion string } func timeConversion(s string) string { var conversion Conversion [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42995","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42995","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=42995"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42995\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}