{"id":46191,"date":"2025-04-21T05:52:30","date_gmt":"2025-04-21T05:52:30","guid":{"rendered":"https:\/\/www.carmatec.com\/?p=46191"},"modified":"2025-12-31T07:38:47","modified_gmt":"2025-12-31T07:38:47","slug":"%e5%9b%b2%e7%a2%81%e3%81%a7%e6%97%a5%e4%bb%98%e3%81%a8%e6%99%82%e5%88%bb%e3%82%92%e6%89%b1%e3%81%86%e5%ae%9f%e8%b7%b5%e3%82%ac%e3%82%a4%e3%83%89","status":"publish","type":"post","link":"https:\/\/www.carmatec.com\/ja\/blog\/mastering-date-and-time-handling-in-go-a-practical-guide\/","title":{"rendered":"Go\u3067\u65e5\u4ed8\u3068\u6642\u523b\u306e\u6271\u3044\u3092\u30de\u30b9\u30bf\u30fc\u3059\u308b\uff1a\u5b9f\u8df5\u30ac\u30a4\u30c9"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"46191\" class=\"elementor elementor-46191\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-9d73a4a e-flex e-con-boxed e-con e-parent\" data-id=\"9d73a4a\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-72c3bfd elementor-widget elementor-widget-text-editor\" data-id=\"72c3bfd\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">\u65e5\u4ed8\u3068\u6642\u523b\u3092\u6271\u3046\u3053\u3068\u306f\u3001API\u306e\u69cb\u7bc9\u3001\u30bf\u30b9\u30af\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u30ed\u30ae\u30f3\u30b0\u306a\u3069\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u672c\u7684\u306a\u5074\u9762\u3067\u3059\u3002Go\u3067\u306f <\/span><span style=\"font-weight: 400;\">\u6642\u9593<\/span><span style=\"font-weight: 400;\"> \u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u65e5\u4ed8\u3001\u6642\u9593\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3001\u671f\u9593\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306e\u5805\u7262\u3067\u76f4\u611f\u7684\u306a\u65b9\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3053\u306e\u30ac\u30a4\u30c9\u3067\u306f <\/span><span style=\"font-weight: 400;\">\u6642\u9593<\/span><span style=\"font-weight: 400;\"> \u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u304b\u3089\u9ad8\u5ea6\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u307e\u3067\u3001\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u6700\u5f8c\u306b\u306f\u3001Go\u3067\u306e\u65e5\u4ed8\u3068\u6642\u523b\u306e\u6271\u3044\u3092\u30de\u30b9\u30bf\u30fc\u3059\u308b\u81ea\u4fe1\u304c\u3064\u304f\u3067\u3057\u3087\u3046\u3002<\/span><\/p><h3><b>\u65e5\u6642\u306e\u6271\u3044\u304c\u91cd\u8981\u306a\u7406\u7531<\/b><\/h3><p><span style=\"font-weight: 400;\">\u65e5\u4ed8\u3068\u6642\u523b\u306f\u591a\u304f\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u91cd\u8981\u3067\u3042\u308b\uff1a<\/span><\/p><ul><li style=\"font-weight: 400;\" aria-level=\"1\"><b>API<\/b><span style=\"font-weight: 400;\"> \u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3057\u3001\u89e3\u6790\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/span><\/li><li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u30fc<\/b><span style=\"font-weight: 400;\"> \u30bf\u30b9\u30af\u306e\u6b63\u78ba\u306a\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u3002<\/span><\/li><li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u904e\u53bb\u30ed\u30b0<\/b><span style=\"font-weight: 400;\"> \u30a4\u30d9\u30f3\u30c8\u3092\u8ffd\u8de1\u3059\u308b\u305f\u3081\u306b\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u4f7f\u7528\u3059\u308b\u3002<\/span><\/li><li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9<\/b> \u30ed\u30fc\u30ab\u30e9\u30a4\u30ba\u3055\u308c\u305f\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u65e5\u4ed8\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/li><\/ul><p><span style=\"font-weight: 400;\">\u30b4\u30fc\u30ba <code>\u6642\u9593<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u30b7\u30f3\u30d7\u30eb\u304b\u3064\u5f37\u529b\u306b\u8a2d\u8a08\u3055\u308c\u3066\u304a\u308a\u3001\u3053\u308c\u3089\u306e\u30b7\u30ca\u30ea\u30aa\u3092\u52b9\u7387\u7684\u306b\u51e6\u7406\u3059\u308b\u30c4\u30fc\u30eb\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u5927\u304d\u304f\u4f9d\u5b58\u3059\u308b\u3044\u304f\u3064\u304b\u306e\u8a00\u8a9e\u3068\u306f\u7570\u306a\u308a\u3001Go\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5fc5\u8981\u306a\u3059\u3079\u3066\u306e\u3082\u306e\u3067\u3042\u308b\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u3055\u3063\u305d\u304f\u4f7f\u3063\u3066\u307f\u3088\u3046\uff01<\/span><\/p><h3><b>\u30bf\u30a4\u30e0\u30d1\u30c3\u30b1\u30fc\u30b8\u3067\u59cb\u3081\u308b<\/b><\/h3><p><span style=\"font-weight: 400;\">\u306e <code>\u6642\u9593<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u306fGo\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u306e\u4e00\u90e8\u306a\u306e\u3067\u3001\u5916\u90e8\u4f9d\u5b58\u306f\u5fc5\u8981\u306a\u3044\u3002\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u304f\u3060\u3055\u3044\uff1a<\/span><\/p><p><span style=\"font-weight: 400;\"><code>\u884c\u304f<\/code><br \/>\u30a4\u30f3\u30dd\u30fc\u30c8 \"time\"<\/span><\/p><p><span style=\"font-weight: 400;\">\u306e\u30b3\u30a2\u30bf\u30a4\u30d7\u3002 <code>\u6642\u9593<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u3067\u3042\u308b\uff1a<\/span><\/p><ul><li style=\"font-weight: 400;\" aria-level=\"1\"><code>\u6642\u9593<\/code>:\u7279\u5b9a\u306e\u6642\u70b9\u3092\u8868\u3059\uff08\u4f8b\uff1a\"2025-04-21 10:30:00\"\uff09\u3002<\/li><li style=\"font-weight: 400;\" aria-level=\"1\"><code>\u6642\u9593<\/code>:\u6642\u9593\u306e\u9577\u3055\u3092\u8868\u3059\uff08\u4f8b\uff1a5\u6642\u959330\u79d2\uff09\u3002<\/li><li style=\"font-weight: 400;\" aria-level=\"1\"><code>\u6642\u9593.\u5834\u6240<\/code>:\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u8868\u3059\uff08\u4f8b\uff1a\"America\/New_York\"\uff09\u3002<\/li><\/ul><p><span style=\"font-weight: 400;\">\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u304b\u3089\u59cb\u3081\u3088\u3046\u3002<\/span><\/p><h3><b>\u73fe\u5728\u306e\u65e5\u4ed8\u3068\u6642\u523b\u306e\u64cd\u4f5c<\/b><\/h3><p><span style=\"font-weight: 400;\">\u73fe\u5728\u306e\u65e5\u4ed8\u3068\u6642\u523b\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f <code>time.Now()<\/code>:<br \/><\/span><span style=\"font-weight: 400;\"><code>\u884c\u304f<\/code><br \/><\/span><span style=\"font-weight: 400;\">\u30d1\u30c3\u30b1\u30fc\u30b8\u30e1\u30a4\u30f3<\/span><\/p><pre><span style=\"font-weight: 400;\">\u30a4\u30f3\u30dd\u30fc\u30c8 (<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\"fmt\"<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u6642\u9593<\/span>\n<span style=\"font-weight: 400;\">)<\/span>\n<span style=\"font-weight: 400;\">\nfunc main() {<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0now := time.Now()<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0fmt.Println(\"Current time:\", now)<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/pre><p><span style=\"font-weight: 400;\">\u3053\u308c\u306f\u6b21\u306e\u3088\u3046\u306a\u51fa\u529b\u3060\uff1a<\/span><\/p><p><span style=\"font-weight: 400;\">\u73fe\u5728\u6642\u523b: 2025-04-21 10:30:45.123456789 +0000 UTC<\/span><\/p><p><span style=\"font-weight: 400;\">\u306e <code>\u6642\u9593<\/code> \u5024\u306b\u306f\u3001\u65e5\u4ed8\u3001\u6642\u523b\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306fUTC\uff09\u304c\u542b\u307e\u308c\u307e\u3059\u3002\u5e74\u3001\u6708\u3001\u6642\u9593\u306a\u3069\u306e\u500b\u3005\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u62bd\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff1a<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">\u5e74 := now.Year() \/\/ \u4f8b\uff1a2025\u5e74<\/span>\n<span style=\"font-weight: 400;\">month := now.Month() \/\/ \u4f8b\uff1a4\u6708<\/span>\n<span style=\"font-weight: 400;\">day := now.Day() \/\/ \u4f8b\uff1a21\u65e5<\/span>\n<span style=\"font-weight: 400;\">hour := now.Hour() \/\/ \u4f8b\uff1a10<\/span>\n<span style=\"font-weight: 400;\">minute := now.Minute() \/\/ \u4f8b\uff1a30<\/span>\n<span style=\"font-weight: 400;\">second := now.Second() \/\/ \u4f8b\uff1a45<\/span>\n\n<span style=\"font-weight: 400;\">fmt.Printf(\"Date: %d-%02d-%02d\\n\", year, month, day)<\/span>\n<span style=\"font-weight: 400;\">fmt.Printf(\"Time: %02d:%02d:%02d\\n\", hour, minute, second)<\/span><\/pre><p><span style=\"font-weight: 400;\">\u51fa\u529b\uff1a<\/span><\/p><p><span style=\"font-weight: 400;\">\u65e5\u4ed8: 2025-04-21<br \/><\/span><span style=\"font-weight: 400;\">\u6642\u9593\uff1a10:30:45<\/span><\/p><p><span style=\"font-weight: 400;\">\u3053\u308c\u306f\u3001\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306e\u7279\u5b9a\u306e\u90e8\u5206\u3092\u8a18\u9332\u3057\u305f\u308a\u8868\u793a\u3057\u305f\u308a\u3059\u308b\u306e\u306b\u4fbf\u5229\u3067\u3059\u3002<\/span><\/p><h3><b>\u65e5\u4ed8\u306e\u89e3\u6790\u3068\u66f8\u5f0f\u8a2d\u5b9a<\/b><\/h3><p><span style=\"font-weight: 400;\">\u65e5\u4ed8\u306e\u89e3\u6790\u3068\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u5bfe\u3059\u308bGo\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u306f\u30e6\u30cb\u30fc\u30af\u3060\u3002\u306e\u3088\u3046\u306a\u66f8\u5f0f\u6307\u5b9a\u5b50\u3092\u4f7f\u3046\u306e\u3067\u306f\u306a\u304f <code>%Y<\/code> \u307e\u305f\u306f <code>%m<\/code> (\u4ed6\u306e\u8a00\u8a9e\u3067\u306f\u4e00\u822c\u7684\uff09\u3001Go\u306f\u53c2\u7167\u6642\u9593\u3092\u4f7f\u3046\uff1a <b>2006\u5e741\u67082\u65e5 15\u664204\u520605\u79d2<\/b> (\u3068\u3057\u3066\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3055\u308c\u308b <code>2006-01-02 15:04:05<\/code>).\u3053\u306e\u65e5\u4ed8\u304c\u9078\u3070\u308c\u305f\u306e\u306f\u3001\u899a\u3048\u3084\u3059\u304f\u3001\u56f2\u7881\u306e\u8a95\u751f\u5e74\uff082006\u5e74\uff09\u3068\u4e00\u81f4\u3057\u3066\u3044\u308b\u304b\u3089\u3060\u3002<\/span><\/p><h3><b>\u65e5\u4ed8\u306e\u66f8\u5f0f\u8a2d\u5b9a<\/b><\/h3><p><span style=\"font-weight: 400;\">\u3092\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3059\u308b\u3002 <code>\u6642\u9593<\/code> \u5024\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u306b\u306f <code>time.Format()<\/code> \u3092\u3001\u57fa\u6e96\u6642\u523b\u306b\u57fa\u3065\u3044\u305f\u30ec\u30a4\u30a2\u30a6\u30c8\u6587\u5b57\u5217\u3067\u8fd4\u3057\u307e\u3059\uff1a<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">now := time.Now()<\/span>\n<span style=\"font-weight: 400;\">formatted := now.Format(\"2006-01-02 15:04:05\")<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"Formatted time:\", formatted)<\/span><\/pre><p><span style=\"font-weight: 400;\">\u51fa\u529b\uff1a<\/span><\/p><p><span style=\"font-weight: 400;\">\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u6642\u9593\uff1a2025-04-21 10:30:45<\/span><\/p><p><span style=\"font-weight: 400;\">\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(now.Format(\"Mon, Jan 2, 2006\"))\/\/ \u4f8b\uff1a2025\u5e744\u670821\u65e5\uff08\u6708<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(now.Format(\"3:04 PM\"))           \/\/ \u4f8b\uff1a\u5348\u524d10\u664230\u5206<\/span><\/pre><h3><b>\u65e5\u4ed8\u306e\u89e3\u6790<\/b><\/h3><p><span style=\"font-weight: 400;\">\u6587\u5b57\u5217\u3092 <code>\u6642\u9593<\/code> \u5024\u3092\u4f7f\u7528\u3059\u308b\u3002 <code>time.Parse()<\/code>:<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">dateStr := \"2025-04-21 10:30:00\"<\/span>\n<span style=\"font-weight: 400;\">\u30ec\u30a4\u30a2\u30a6\u30c8 := \"2006-01-02 15:04:05\"<\/span>\n<span style=\"font-weight: 400;\">t, err := time.Parse(layout, dateStr)<\/span>\n<span style=\"font-weight: 400;\">\u3082\u3057err != nil {\u306a\u3089<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0fmt.Println(\"Error parsing time:\", err)<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u623b\u308b<\/span>\n<span style=\"font-weight: 400;\">}<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"Parsed time:\", t)<\/span><\/pre><p><span style=\"font-weight: 400;\">\u51fa\u529b\uff1a<\/span><\/p><p><span style=\"font-weight: 400;\">\u89e3\u6790\u6642\u9593\uff1a2025-04-21 10:30:00 +0000 UTC<\/span><\/p><p><span style=\"font-weight: 400;\">\u6587\u5b57\u5217\u304c\u30ec\u30a4\u30a2\u30a6\u30c8\u3068\u4e00\u81f4\u3057\u306a\u3044\u5834\u5408\u3001 <code>time.Parse()<\/code> \u306f\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u306e\u3067\u3001\u5e38\u306b\u30a8\u30e9\u30fc\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/span><\/p><p><span style=\"font-weight: 400;\">\u4fbf\u5229\u306a\u3088\u3046\u306b\u3001Go\u306f\u6b21\u306e\u3088\u3046\u306a\u5b9a\u7fa9\u6e08\u307f\u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002 <code>\u30bf\u30a4\u30e0<\/code> \u6a19\u6e96\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u5834\u5408\uff1a<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">t, err = time.Parse(time.RFC3339, \"2025-04-21T10:30:00Z\")<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"Parsed RFC3339 time:\", t)<\/span><\/pre><h3><b>\u65e5\u4ed8\u3068\u6642\u523b\u306e\u64cd\u4f5c<\/b><\/h3><p><span style=\"font-weight: 400;\">\u306e <code>\u6642\u9593<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u3068\u3001\u65e5\u4ed8\u3084\u6642\u523b\u306e\u7b97\u8853\u6f14\u7b97\u304c\u7c21\u5358\u306b\u3067\u304d\u308b\u3002<\/span><\/p><h3><b>\u6642\u9593\u306e\u8db3\u3057\u7b97\u3068\u5f15\u304d\u7b97<\/b><\/h3><p><span style=\"font-weight: 400;\">\u7528\u9014 <code>\u8ffd\u52a0()<\/code> \u3092\u8ffd\u52a0\u3059\u308b\u3002 <code>\u6642\u9593<\/code> \u3078\u306e <code>\u6642\u9593<\/code>:<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">now := time.Now()<\/span>\n<span style=\"font-weight: 400;\">future := now.Add(24 * time.Hour) \/\/ 1\u65e5\u8db3\u3059<\/span>\n<span style=\"font-weight: 400;\">past := now.Add(-2 * time.Hour) \/\/ 2\u6642\u9593\u5f15\u304f<\/span>\n\n<span style=\"font-weight: 400;\">fmt.Println(\"Now:\", now)<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"Future:\", future)<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"\u904e\u53bb:\", \u904e\u53bb)<\/span>\n<span style=\"font-weight: 400;\">\u6642\u9593<\/span><span style=\"font-weight: 400;\"> \u306e\u3088\u3046\u306a\u5b9a\u6570\u3092\u4f7f\u7528\u3057\u3066\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002 <\/span><span style=\"font-weight: 400;\">\u6642\u9593<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\u6642\u9593.\u5206<\/span><span style=\"font-weight: 400;\">\u3042\u308b\u3044\u306f <\/span><span style=\"font-weight: 400;\">\u6642\u9593.\u79d2<\/span><span style=\"font-weight: 400;\">.\u30c7\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u89e3\u6790\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\uff1a<\/span>\n\n<span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">duration, _ := time.ParseDuration(\"1h30m\")<\/span>\n<span style=\"font-weight: 400;\">future = now.Add(\u671f\u9593)<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"1\u6642\u959330\u5206\u5f8c:\", future)<\/span><\/pre><h3><b>\u6642\u5dee\u306e\u8a08\u7b97<\/b><\/h3><p><span style=\"font-weight: 400;\">2\u3064\u306e\u6642\u9593\u306e\u5dee\u3092\u6c42\u3081\u308b\u306b\u306f <code>\u30b5\u30d6()<\/code>:<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">start := time.Now()<\/span>\n<span style=\"font-weight: 400;\">time.Sleep(2 * time.Second) \/\/ \u3044\u304f\u3064\u304b\u306e\u4f5c\u696d\u3092\u30b7\u30df\u30e5\u30ec\u30fc\u30c8\u3059\u308b<\/span>\n<span style=\"font-weight: 400;\">end := time.Now()<\/span>\n\n<span style=\"font-weight: 400;\">elapsed := end.Sub(start)<\/span>\n<span style=\"font-weight: 400;\">fmt.Printf(\"\u7d4c\u904e\u6642\u9593\uff1a%v\\n\", elapsed)<\/span><\/pre><p><span style=\"font-weight: 400;\">\u51fa\u529b\uff1a<\/span><\/p><p><span style=\"font-weight: 400;\">\u7d4c\u904e\u6642\u9593\uff1a2.001234567\u79d2<\/span><\/p><h3><b>\u65e5\u4ed8\u306e\u6bd4\u8f03<\/b><\/h3><p><span style=\"font-weight: 400;\">\u6bd4\u8f03\u3067\u304d\u308b <code>\u6642\u9593<\/code> \u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002 <code>\u524d(), \u5f8c()<\/code>\u3001 \u305d\u3057\u3066 <code>\u30a4\u30b3\u30fc\u30eb()<\/code>:<\/span><\/p><pre><span style=\"font-weight: 400;\">\u884c\u304f<\/span>\n<span style=\"font-weight: 400;\">t1 := time.Now()<\/span>\n<span style=\"font-weight: 400;\">t2 := t1.Add(1 * time.Hour)<\/span>\n\n<span style=\"font-weight: 400;\">fmt.Println(\"t1 before t2?\", t1.Before(t2))\/\/ \u771f<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"t2 after t1?\", t2.After(t1)) \/\/ true<\/span>\n<span style=\"font-weight: 400;\">fmt.Println(\"t1 equal t2?\", t1.Equal(t2)) \/\/ false  \/\/ false<\/span><\/pre><h3><b>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3078\u306e\u5bfe\u5fdc<\/b><\/h3><p><span style=\"font-weight: 400;\">\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306f\u5384\u4ecb\u306a\u3082\u306e\u3067\u3059\u304c\u3001\u56f2\u7881\u306f\u6b21\u306e\u3088\u3046\u306b\u5358\u7d14\u5316\u3057\u307e\u3059\u3002 <code>\u6642\u9593.\u5834\u6240<\/code>.<\/span><\/p><h3><b>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u8aad\u307f\u8fbc\u307f<\/b><\/h3><p>\u7279\u5b9a\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3067\u4f5c\u696d\u3059\u308b\u306b\u306f <code>time.LoadLocation()<\/code>:<\/p><pre>\u884c\u304f\nloc, err := time.LoadLocation(\"America\/New_York\")\nif err != nil { \u3082\u3057err !\nfmt.Println(\"Error loading location:\", err)\n\u30ea\u30bf\u30fc\u30f3\n}\nnyTime := time.Now().In(loc)\nfmt.Println(\"New York time:\", nyTime)<\/pre><p>\u306e <code>time.LoadLocation()<\/code> \u95a2\u6570\u306f\u3001IANA\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u30fb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08\u4f8b\uff1a\"America\/New_York\"\u3001\"Asia\/Tokyo\"\uff09\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u5834\u6240\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u3001Go\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067UTC\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p><h3><strong>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u9593\u306e\u5909\u63db<\/strong><\/h3><p>\u6642\u523b\u3092\u5225\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306b\u5909\u63db\u3059\u308b\u306b\u306f <code>\u30a4\u30f3()<\/code>:<\/p><pre>\u884c\u304f\nutcTime := time.Now()\nloc, _ = time.LoadLocation(\"\u30a2\u30b8\u30a2\/\u6771\u4eac\")\ntokyoTime := utcTime.In(loc)\nfmt.Println(\"UTC time:\", utcTime)\nfmt.Println(\"Tokyo time:\", tokyoTime)<\/pre><h3><strong>UTC\u3068\u73fe\u5730\u6642\u9593\u306e\u4f7f\u7528<\/strong><\/h3><p>UTC\u306e\u5834\u5408\u306fUTC()\u3092\u4f7f\u3046\uff1a<\/p><pre>\u884c\u304f\nutc := time.Now().UTC()\nfmt.Println(\"UTC time:\", utc)\n\u30b7\u30b9\u30c6\u30e0\u306e\u30ed\u30fc\u30ab\u30eb\u30fb\u30bf\u30a4\u30e0\u30fb\u30be\u30fc\u30f3\u306b\u306f\u3001Local()\u3092\u4f7f\u7528\u3059\u308b\uff1a\n\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002\nlocal := time.Now().Local()\nfmt.Println(\"Local time:\", local)<\/pre><h3><strong>\u5b9f\u8df5\u4f8b<\/strong><\/h3><p>\u5b9f\u969b\u306e\u30b7\u30ca\u30ea\u30aa\u3092\u63a2\u3063\u3066\u307f\u3088\u3046\u3002<\/p><h3><strong>\u30bf\u30b9\u30af\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0<\/strong><\/h3><p>\u30bf\u30b9\u30af\u3092\u4e00\u5b9a\u9593\u9694\u3067\u5b9f\u884c\u3059\u308b\u306b\u306f\u3001time.Tick()\u3092\u4f7f\u3046\uff1a<\/p><pre>\u884c\u304f\nticker := time.Tick(2 * time.Second)\nfor t := ticker\u306e\u7bc4\u56f2 {.\n    fmt.Println(\"Tick at\", t)\n}\n1\u56de\u3060\u3051\u9045\u5ef6\u3055\u305b\u308b\u5834\u5408\u306f\u3001time.After()\u3092\u4f7f\u7528\u3057\u307e\u3059\uff1a\n\u884c\u304f\n\u30bb\u30ec\u30af\u30c8\ncase &lt;-time.After(3 * time.Second)\uff1a\n    fmt.Println(&quot;3 \u79d2\u5f8c...&quot;)\n}<\/pre><h3><strong>\u5e74\u9f62\u306e\u8a08\u7b97<\/strong><\/h3><p>\u751f\u5e74\u6708\u65e5\u304b\u3089\u5e74\u9f62\u3092\u8a08\u7b97\u3059\u308b\uff1a<\/p><pre>\u884c\u304f\nbirthStr := \"1990-05-15\"\nbirthTime, _ := time.Parse(\"2006-01-02\", birthStr)\nnow := time.Now()\nage := now.Year() - birthTime.Year()\nif now.YearDay() &lt; birthTime.YearDay() { \u3082\u3057now.YearDay() &lt; birthTime.YearDay()\u306a\u3089\nage-- \/\/ \u8a95\u751f\u65e5\u304c\u4eca\u5e74\u3067\u306a\u3044\u5834\u5408\u306f\u8abf\u6574\u3059\u308b\n}\nfmt.Printf(&quot;Age: %dTn&quot;, age)<\/pre><h3><strong>API\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8<\/strong><\/h3><p>API\u306f\u3057\u3070\u3057\u3070ISO 8601 (RFC3339)\u306e\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u4f7f\u7528\u3059\u308b\uff1a<\/p><pre>\u884c\u304f\nnow := time.Now()\napiTime := now.Format(time.RFC3339)\nfmt.Println(\"API timestamp:\", apiTime)<\/pre><h3><strong>\u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/strong><\/h3><h5><strong>\u843d\u3068\u3057\u7a74<\/strong><\/h5><ul><li><strong>\u8aa4\u3063\u305f\u30ec\u30a4\u30a2\u30a6\u30c8\uff1a<\/strong> \u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u306e\u30df\u30b9\u30de\u30c3\u30c1 <code>time.Parse()<\/code> \u307e\u305f\u306f <code>time.Format()<\/code> \u306f\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3060\u3002\u5e38\u306b\u57fa\u6e96\u6642\u9593(<code>2006-01-02 15:04:05<\/code>).<\/li><li><strong>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u60f3\u5b9a\uff1a<\/strong> \u3059\u3079\u3066\u306e\u6642\u9593\u304cUTC\u307e\u305f\u306f\u30ed\u30fc\u30ab\u30eb\u30bf\u30a4\u30e0\u3067\u3042\u308b\u3068\u4eee\u5b9a\u3059\u308b\u3068\u3001\u30d0\u30b0\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306f\u5e38\u306b\u660e\u793a\u7684\u306b\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/li><li><strong>\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3059\u308b<\/strong> \u306a\u3069\u306e\u6a5f\u80fd\u304c\u3042\u308b\u3002 <code>time.Parse()<\/code> \u305d\u3057\u3066 <code>time.LoadLocation()<\/code> \u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u3002\u5e38\u306b\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3002<\/li><\/ul><h5><strong>\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/strong><\/h5><ul><li><strong>\u4fdd\u7ba1\u306b\u306fUTC\u3092\u4f7f\u3046\uff1a<\/strong> \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u6df7\u4e71\u3092\u907f\u3051\u308b\u305f\u3081\u3001\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306fUTC\u3067\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/li><li><strong>\u5165\u529b\u3092\u691c\u8a3c\u3059\u308b\uff1a<\/strong> \u30e6\u30fc\u30b6\u30fc\u304b\u3089\u63d0\u4f9b\u3055\u308c\u305f\u65e5\u4ed8\u3092\u89e3\u6790\u3059\u308b\u5834\u5408\u306f\u3001\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u691c\u8a3c\u3057\u3001\u30a8\u30e9\u30fc\u3092\u512a\u96c5\u306b\u51e6\u7406\u3057\u307e\u3059\u3002<\/li><li><strong>\u5b9a\u7fa9\u6e08\u307f\u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u6d3b\u7528\u3059\u308b\uff1a<\/strong> \u306e\u3088\u3046\u306a\u5b9a\u6570\u3092\u4f7f\u7528\u3059\u308b\u3002 <code>\u30bf\u30a4\u30e0<\/code> \u6a19\u6e96\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u5834\u5408\u3002<\/li><li><strong>\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9<\/strong> \u3092\u983b\u7e41\u306b\u547c\u3073\u51fa\u3059\u3053\u3068\u306f\u907f\u3051\u3066\u304f\u3060\u3055\u3044\u3002 <code>time.Now()<\/code> \u30bf\u30a4\u30c8\u306a\u30eb\u30fc\u30d7\u3067\u306f\u3001\u6bd4\u8f03\u7684\u9ad8\u4fa1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u304b\u3089\u3060\u3002<\/li><\/ul><h3><strong>\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u30e9\u30a4\u30d6\u30e9\u30ea<\/strong><\/h3><p>\u4e00\u65b9 <code>\u6642\u9593<\/code> \u306e\u3088\u3046\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u5341\u5206\u3067\u3059\u3002 <code>github.com\/jinzhu\/now<\/code> \u3092\u4f7f\u3048\u3070\u3001\u8907\u96d1\u306a\u64cd\u4f5c\uff08\u4f8b\u3048\u3070\u3001\u9031\u306e\u59cb\u307e\u308a\u3092\u898b\u3064\u3051\u308b\u306a\u3069\uff09\u3092\u7c21\u7565\u5316\u3067\u304d\u308b\u3002\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u5341\u5206\u306a\u5834\u5408\u304c\u591a\u3044\u306e\u3067\u3001\u4f7f\u7528\u306f\u63a7\u3048\u3081\u306b\u3002<\/p><h2><strong>\u7d50\u8ad6<\/strong><\/h2><p>\u30b4\u30fc\u30ba <code>\u6642\u9593<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u65e5\u4ed8\u3001\u6642\u523b\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6271\u3046\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u66f8\u5f0f\u8a2d\u5b9a\u3084\u89e3\u6790\u304b\u3089\u6f14\u7b97\u3084\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u307e\u3067\u3001\u5805\u7262\u306a\u6642\u9593\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u3059\u3079\u3066\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u6838\u3068\u306a\u308b\u6982\u5ff5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067<code>-\u6642\u9593.\u6642\u9593, \u6642\u9593.\u671f\u9593<\/code>\u3001 \u305d\u3057\u3066 <code>\u6642\u9593.\u5834\u6240<\/code>\u305d\u3057\u3066\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306b\u5f93\u3046\u3053\u3068\u3067\u3001\u6700\u3082\u8907\u96d1\u306a\u65e5\u4ed8\u3068\u6642\u523b\u306e\u30b7\u30ca\u30ea\u30aa\u3067\u3082\u81ea\u4fe1\u3092\u6301\u3063\u3066\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p><p>\u672c\u30ac\u30a4\u30c9\u306e\u4f8b\u3092\u4f7f\u3063\u3066\u5b9f\u9a13\u3057\u3001\u4ee5\u4e0b\u306e\u3053\u3068\u3092\u63a2\u6c42\u3057\u3066\u304f\u3060\u3055\u3044\u3002 <a href=\"https:\/\/pkg.go.dev\/time\">\u56f2\u7881\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u305d\u3057\u3066\u3001\u72ec\u81ea\u306e\u6642\u9593\u30d9\u30fc\u30b9\u306e\u6a5f\u80fd\u3092\u69cb\u7bc9\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\u30bf\u30b9\u30af\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u30ed\u30b0\u3001API\u30ec\u30b9\u30dd\u30f3\u30b9\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306a\u3069\u3001Go\u3067\u306e\u65e5\u4ed8\u3068\u6642\u523b\u306e\u53d6\u308a\u6271\u3044\u3092\u30de\u30b9\u30bf\u30fc\u3059\u308c\u3070\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4fe1\u983c\u6027\u3068\u4f7f\u3044\u3084\u3059\u3055\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002\u9ad8\u6027\u80fd\u3067\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092 <a href=\"https:\/\/www.carmatec.com\/ja\/\">\u30ab\u30fc\u30de\u30c6\u30c3\u30af\u306e<\/a> \u30a8\u30ad\u30b9\u30d1\u30fc\u30c8 <a href=\"https:\/\/www.carmatec.com\/ja\/golang%e9%96%8b%e7%99%ba%e4%bc%9a%e7%a4%be\/\">Golang\u958b\u767a\u30b5\u30fc\u30d3\u30b9<\/a> \u73fe\u4ee3\u306e\u30d3\u30b8\u30cd\u30b9\u30cb\u30fc\u30ba\u306b\u5408\u308f\u305b\u305f<\/p><p>\u00a0<\/p><p>\u00a0<\/p><p>\u00a0<\/p><p>\u00a0<\/p><p>\u00a0<\/p><p>\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>Handling dates and times is a fundamental aspect of programming, whether you&#8217;re building APIs, scheduling tasks, or logging events. In Go, the time package provides a robust and intuitive way to manage dates, times, time zones, and durations. This guide will walk you through the essentials of the time package, from basic operations to advanced [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":46221,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-46191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/posts\/46191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/comments?post=46191"}],"version-history":[{"count":0,"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/posts\/46191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/media\/46221"}],"wp:attachment":[{"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/media?parent=46191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/categories?post=46191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.carmatec.com\/ja\/wp-json\/wp\/v2\/tags?post=46191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}