{"id":4032,"date":"2023-09-30T12:18:15","date_gmt":"2023-09-30T03:18:15","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=4032"},"modified":"2025-07-10T19:23:23","modified_gmt":"2025-07-10T10:23:23","slug":"%e3%80%90go%e3%80%91%e6%99%82%e5%88%bb%e3%81%ae%e5%8f%96%e3%82%8a%e6%89%b1%e3%81%84","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=4032","title":{"rendered":"\u3010Go\u3011\u73fe\u5728\u6642\u523b\u306e\u53d6\u308a\u6271\u3044"},"content":{"rendered":"\n<p>Go\u3067\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h1 class=\"wp-block-heading\">\u57fa\u672c<\/h1>\n\n\n\n<p>\u307e\u305a\u306f\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc main() {\n\n\t\/\/ \u73fe\u5728\u6642\u523b\n\tfmt.Println(time.Now()) \/\/ 2023-09-30 12:11:32.046565 +0900 JST m=+0.000120618\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>\u5e74\u6708\u65e5\u3068\u6642\u523b\u304c\u5206\u304b\u308a\u307e\u3059\u304c\u3001\u305d\u306e\u4ed6\u306b\u96e3\u3057\u305d\u3046\u306a\u6587\u5b57\u3068\u6570\u5b57\u304c\u3042\u308a\u307e\u3059\u306d\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u73fe\u5728\u65e5\u4ed8\u6642\u523b\u306e\u8868\u793a<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u30d5\u30a9\u30fc\u30de\u30c3\u30c8<\/h2>\n\n\n\n<p>\u3088\u304f\u4f7f\u3046\u3067\u3042\u308d\u3046\u65e5\u4ed8\u306e\u5f62\u5f0f YYYY-MM-DD HH::MM::SS \u3067\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc main() {\n\tfmt.Println(time.Now().Format(time.DateTime)) \/\/ 2023-09-30 12:23:22\n\tfmt.Println(time.DateTime)                    \/\/ 2006-01-02 15:04:05\n}\n<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u8aac<\/h3>\n\n\n\n<p>Format\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3068\u73fe\u5728\u6642\u523b\u3092\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3057\u3066\u8868\u793a\u3067\u304d\u307e\u3059\u3002Format\u30e1\u30bd\u30c3\u30c9\u306b\u306f\u8868\u793a\u3057\u305f\u3044\u65e5\u4ed8\u5f62\u5f0f\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br>time\u306b\u306f\u3044\u304f\u3064\u304b\u306e\u5b9a\u6570\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u3066\u3001\u305d\u308c\u3089\u306e\u3044\u304f\u3064\u304b\u306f\u65e5\u4ed8\u5f62\u5f0f\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u3067\u3059\u3002\u4eca\u56de\u306f time.DateTime \u3092\u4f7f\u7528\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u4e2d\u8eab\u306f 2006-01-02 15:04:05 \u306b\u306a\u308a\u307e\u3059\u3002\u5f93\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d5\u30a9\u30de\u30c3\u30c8\u3092\u6307\u5b9a\u3059\u308b\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc main() {\n\tfmt.Println(time.Now().Format(&quot;2006-01-02 15:04:05&quot;)) \/\/ 2023-09-30 12:32:18\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u6307\u5b9a\u3067\u304d\u308b\u5b9a\u6570\u306f\u516c\u5f0f\u30da\u30fc\u30b8\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u8003<\/span>\n<p><\/p>\n<p><a href=\"https:\/\/pkg.go.dev\/time#pkg-constants\" rel=\"noopener\" target=\"_blank\">Time\u5b9a\u6570<\/a><\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3<\/h2>\n\n\n\n<p>\u304a\u305d\u3089\u304f\u3001\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u3001OS\u306e\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3(\u6b63\u78ba\u306b\u306fGo\u306e\u5b9f\u884c\u74b0\u5883)\u304c\u4f7f\u7528\u3055\u308c\u308b\u3068\u4e88\u60f3\u3057\u307e\u3059\u3002<br>\u57fa\u672c\u3067\u8868\u793a\u3057\u305f\u901a\u308a\u3001\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u306fJST\u306e\u3088\u3046\u3067\u3059\u3002\u4ee5\u4e0b\u306f\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u305f\u969b\u306e\u4e00\u90e8\u629c\u7c8b\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>+0900 JST<\/code><\/pre><\/div>\n\n\n\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u5b9f\u884c\u3055\u308c\u308b\u74b0\u5883\u306f\u69d8\u3005\u3067\u3059\u3002\u4f55\u3089\u304b\u306e\u7406\u7531\u304c\u3042\u3063\u3066OS\u306e\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u304cUTC\u3068\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002\u305d\u3093\u306a\u4e8b\u3082\u3042\u308b\u306e\u3067\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u6307\u5b9a\u3059\u3079\u304d\u4e8b\u9805\u3067\u3059\u3002<br>\u305d\u308c\u3067\u306f\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc main() {\n\n\t\/\/ JST\u3067\u8868\u793a\u3059\u308b\n\tjst, err := time.LoadLocation(&quot;Asia\/Tokyo&quot;)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(time.Now().In(jst)) \/\/ 2023-09-30 12:54:16.768134 +0900 JST\n\n\t\/\/ UTC\u3067\u8868\u793a\u3059\u308b\u3002\n\tutc, err := time.LoadLocation(&quot;UTC&quot;)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(time.Now().In(utc)) \/\/ 2023-09-30 03:54:16.768186 +0000 UTC\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>LoadLocation\u30e1\u30bd\u30c3\u30c9\u306b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002In\u30e1\u30bd\u30c3\u30c9\u306b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3059\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3068\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3<\/h2>\n\n\n\n<p>\u6700\u5f8c\u306b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3068\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc main() {\n\n\t\/\/ JST\u3067\u8868\u793a\u3059\u308b\n\tjst, err := time.LoadLocation(&quot;Asia\/Tokyo&quot;)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(time.Now().In(jst).Format(time.DateTime)) \/\/ 2023-09-30 13:01:29\n\n\t\/\/ UTC\u3067\u8868\u793a\u3059\u308b\u3002\n\tutc, err := time.LoadLocation(&quot;UTC&quot;)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(time.Now().In(utc).Format(time.DateTime)) \/\/ 2023-09-30 04:01:29\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c\u3092\u898b\u308b\u3068UTC\u306fJST-9\u6642\u9593\u3067\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u4e8b\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Time\u578b<\/h1>\n\n\n\n<p>\u3053\u308c\u307e\u3067\u306b\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001Go\u3067\u306f\u65e5\u4ed8\u3092\u4e3b\u306bTime\u578b\u3067\u6271\u3046\u4e8b\u306b\u610f\u8b58\u3057\u3066\u4e0b\u3055\u3044\u3002time.Now()\u306e\u623b\u308a\u5024\u306f\u6587\u5b57\u5217\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002Now\u30e1\u30bd\u30c3\u30c9\u306fTime\u578b\u3092\u8fd4\u3057\u307e\u3059\u3002\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3044\u305f\u3044\u5834\u5408\u3001string\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001Format\u30e1\u30bd\u30c3\u30c9\u306f\u6587\u5b57\u5217\u3092\u8fd4\u5374\u3059\u308b\u306e\u3067\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3048\u308b\u4e8b\u306b\u6ce8\u610f\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;reflect&quot;\n\t&quot;time&quot;\n)\n\nfunc main() {\n\tfmt.Println(reflect.TypeOf(time.Now())) \/\/ time.Time\n\n\tnowStr := time.Now().String()\n\tfmt.Println(nowStr) \/\/ 2023-10-02 17:50:22.918421 +0900 JST m=+0.000082516\n\tfmt.Println(reflect.TypeOf(nowStr)) \/\/ string\n\n\tnowFmt := time.Now().Format(time.DateTime)\n\tfmt.Println(nowFmt) \/\/ 2023-10-02 17:50:22\n\tfmt.Println(reflect.TypeOf(nowFmt)) \/\/ string\n}\n<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u7279\u306b\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u3067\u73fe\u5728\u6642\u523b\u3092\u8868\u793a\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":5,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-4032","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4032"}],"version-history":[{"count":12,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4032\/revisions"}],"predecessor-version":[{"id":4054,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4032\/revisions\/4054"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/5"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}