最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

GO中的時間操作總結(jié)(time&dateparse)

 更新時間:2023年09月19日 15:13:57   作者:橙子家  
日常開發(fā)過程中,對于時間的操作可謂是無處不在,但是想實現(xiàn)時間自由還是不簡單的,多種時間格式容易混淆,本文為大家整理了一下GO中的時間操作,有需要的可以參考下

〇、前言

日常開發(fā)過程中,對于時間的操作可謂是無處不在,但是想實現(xiàn)時間自由還是不簡單的,多種時間格式容易混淆,那么本文將進行梳理,一起學習下。

官方提供的庫是 time,功能很全面,本文也會詳細介紹。

還有另外一個開源庫 dateparse,使用起來比較方便,本文也會將加入示例測試出結(jié)果,以展示其優(yōu)點。

一、time 庫

1.1 Time 類型的結(jié)構(gòu)

go 通過time.Now()來取當前時間,打印出來如下:

2023-09-15 17:59:14.2642387 +0800 CST m=+0.010202701

這里存在兩個疑點:1)表示秒級的數(shù)值為什么默認為 7 位?  2)最后邊的 m=... 代表什么?

1)對于時間戳來說,一般采用秒級或毫秒級。采用浮點數(shù)或定點數(shù)來表示小數(shù)部分,需要一定的字節(jié)數(shù)來存儲,而為了在大多數(shù)應用場景下滿足足夠的精度,一般會選擇使用7位數(shù)字來表示毫秒級的小數(shù)部分,從而達到既滿足絕大多數(shù)需求又占用盡量上的存儲。

2)m 就是 Monotonic Clocks,意思是單調(diào)時間的,所謂單調(diào),就是只會不停的往前增長,不受校時操作的影響,這個時間是自進程啟動以來的秒數(shù)。

在 go1.9 之后,結(jié)構(gòu)更新為:

type Time struct {
	wall uint64
	ext  int64
	loc *Location
}

Time 結(jié)構(gòu)體中由三部分組成,loc 比較明了,表示時區(qū),wall 和 ext 所存儲的信息規(guī)則相對復雜,根據(jù)文檔的介紹總結(jié)成了下圖:

golang 中的 Time 結(jié)構(gòu),不像很多語言保存 Unix 時間戳(也就是最早只能表示到 1970 年 1 月 1 日),而是至少可以安全的表示 1885 年以來的時間。

下面來取當前時間測試下:

package main
import (
	"encoding/json"
	"fmt"
	"time"
)
func main() {
	now := time.Now() // 取當前時間
	time_now := now
	fmt.Println(time_now)
	for i := 0; i < 5; i++ { // 循環(huán) 0~4 共 5 此
		time_now = time_now.Add(1 * time.Second) // 每次加 1 秒
		fmt.Println(time_now)
	}
	encodeNow, _ := json.Marshal(now) // 轉(zhuǎn) json 編碼
	decodeNow := time.Time{}
	json.Unmarshal(encodeNow, &decodeNow) // 將 json 編碼轉(zhuǎn)回 Time
	fmt.Println(decodeNow)
	equal_r := now.Equal(decodeNow)
	fmt.Println(equal_r)
}

 結(jié)果如下,可見循環(huán)了五次,每次 m 的值都加 1,json 編碼轉(zhuǎn)換后的時間中 m 參數(shù)消失:

1.2 獲取當前時間與格式化

1.2.1 取當前時間

回去當前時間的方法很簡單:

now := time.Now()
fmt.Println(now)
// 2023-09-18 13:51:40.8480546 +0800 CST m=+0.008992401
fmt.Println(now.String())
// 2023-09-18 13:51:40.8480546 +0800 CST m=+0.008992401

1.2.2 時間格式化

Go 語言提供了時間類型格式化函數(shù) Format(),需要注意的是 Go 語言格式化時間模板不是常見的 Y-m-d H:i:s,而是 2006-01-02 15:04:05,也很好記憶(2006 1 2 3 4 5)。

func (t Time) Format(layout string) string {   }

time 庫中,定義了年、月、日、時、分、秒、周、時區(qū)的多種表現(xiàn)形式,如下:

  • 年:   06/2006
  • 月:   1/01/Jan/January
  • 日:   2/02/_2
  • 時:   3/03/15/PM/pm/AM/am
  • 分:   4/04
  • 秒:   5/05
  • 周:   Mon/Monday
  • 時區(qū):-07/-0700/Z0700/Z07:00/-07:00/MST

這些格式的形式配置,可以根據(jù)自己的需求自由組合,一下是部分組合的測試:

package main
import (
	"fmt"
	"time"
)
func main() {
	now := time.Now()
	fmt.Println(now)
	fmt.Println("2006-01-02 15:04:05             output:", now.Format("2006-01-02 15:04:05"))
	fmt.Println("2006-01-02                      output:", now.Format("2006-01-02"))
	fmt.Println("01-02-2006                      output:", now.Format("01-02-2006"))
	fmt.Println("15:03:04                        output:", now.Format("15:03:04"))
	fmt.Println("2006/01/02 15:04                output:", now.Format("2006/01/02 15:04"))
	fmt.Println("15:04 2006/01/02                output:", now.Format("15:04 2006/01/02"))
	fmt.Println("2006#01#02                      output:", now.Format("2006#01#02"))
	fmt.Println("2006$01$02                      output:", now.Format("2006$01$02"))
	fmt.Println("2006-01-02 15:04:05.000         output:", now.Format("2006-01-02 15:04:05.000"))
	fmt.Println("2006-01-02 15:04:05.000000000   output:", now.Format("2006-01-02 15:04:05.000000000"))
	fmt.Println("2006-January-02 15:04:05 Monday output:", now.Format("2006-January-02 15:04:05 Monday"))
	fmt.Println("2006-Jan-02 15:04:05 Mon        output:", now.Format("2006-Jan-02 15:04:05 Mon"))
	fmt.Println("2006-1-2 3:4:5 PM               output:", now.Format("2006-1-2 3:4:5 PM"))
}

字符串類型的日期轉(zhuǎn) Time:

package main
import (
	"fmt"
	"time"
)
func main() {
	t, _ := time.ParseInLocation("2006-01-02", "2023-09-18", time.Local) // time.Local 指定本地時間
	fmt.Println(t)
	t, _ = time.ParseInLocation("2006-01-02 15:04:05", "2023-09-18 17:46:13", time.Local)
	fmt.Println(t)
	t, _ = time.ParseInLocation("2006-01-02 15:04:05", "2023-09-18", time.Local)
	fmt.Println(t) // 當時間字符串和標準字符串不統(tǒng)一時,轉(zhuǎn)化失敗
}

1.2.3 取日期的單個值

日期的組成部分比較多,下面來嘗試取出各個部分的值: 

package main
import (
	"fmt"
	"time"
)
func main() {
	now := time.Now()
	// 返回日期
	year, month, day := now.Date()
	fmt.Printf("日期:%d年%d月%d日\n", year, month, day)
	fmt.Println("年:", now.Year()) // int
	fmt.Println("月:", now.Month()) // time.Month
	fmt.Println("月:", now.Month().String())
	fmt.Println("月:", int(now.Month()))
	fmt.Println("日:", now.Day()) // int
	// 時分秒
	hour, minute, second := now.Clock()
	fmt.Printf("時間:%d:%d:%d\n", hour, minute, second)
	fmt.Println("時:", now.Hour()) // int
	fmt.Println("分:", now.Minute()) // int
	fmt.Println("秒:", now.Second()) // int
	fmt.Println("星期:", now.Weekday()) // time.Weekday
	fmt.Println("星期:", now.Weekday().String()) // 不能得到 一、二。。。
	fmt.Println("星期:", int(now.Weekday()))     // 可以通過取得的 1、2。。。來計算是周幾
	fmt.Println("天數(shù):", now.YearDay()) // int
	fmt.Println("時區(qū):", now.Location())
}

1.3 日期的計算

計算之前或之后一段時間:

package main
import (
	"fmt"
	"time"
)
func main() {
	now := time.Now()
	fmt.Println(now, "(當前時間)")
	// func (t Time) AddDate(years int, months int, days int) Time
	m0 := now.AddDate(1, 1, 1)
	fmt.Println(m0, "(now.AddDate(1,1,1))")
	m00 := now.AddDate(0, 1, 1)
	fmt.Println(m00, "(now.AddDate(0,1,1))")
	// func ParseDuration(s string) (Duration, error)
	// s string:"ns", "us" (or "μs"), "ms", "s", "m", "h"
	t1, _ := time.ParseDuration("1h1m1s") // 亦可:48h1m1s
	m1 := now.Add(t1)
	fmt.Println(m1, "(1小時1分1s之后)")
	t2, _ := time.ParseDuration("-1h1m1s")
	m2 := now.Add(t2)
	fmt.Println(m2, "(1小時1分1s之前)")
	t3, _ := time.ParseDuration("-1h")
	m3 := now.Add(t3 * 3)
	fmt.Println(m3, "(3小時之前)")
}

時間差和比較時間大?。?/strong>

package main
import (
	"fmt"
	"time"
)
func main() {
	now := time.Now()
	fmt.Println(now, "(當前時間)")
	// func (t Time) Sub(u Time) Duration // 取時間差對象
	sub1 := now.Sub(m1)
	fmt.Println(sub1.Hours(), "(相差小時數(shù))")
	fmt.Println(sub1.Minutes(), "(相差分鐘數(shù))")
	// time.Since(t Time) Duration // 返回當前時間與 t 的時間差,返回值是 Duration
	// time.Until(t Time) Duration // 返回 t 與當前時間的時間差,返回值是 Duration
	t1s, _ := time.ParseDuration("-1h")
	m1s := now.Add(t1s)
	fmt.Println(time.Since(m1s), "(Since)")
	fmt.Println(time.Until(m1s), "(Until)")
	// func (t Time) Before(u Time) bool // 如果 t 代表的時間點在 u 之前,返回真;否則返回假
	// func (t Time) After(u Time) bool // 如果 t 代表的時間點在 u 之后,返回真;否則返回假
	// func (t Time) Equal(u Time) bool // 比較時間是否相等,相等返回真;否則返回假
	t1m, _ := time.ParseDuration("1h")
	m1m := now.Add(t1m)
	fmt.Println(m1m)
	fmt.Println(m1m.After(now), "(After(now))")
	fmt.Println(m1m.Before(now), "(Before(now))")
	fmt.Println(now.Equal(m1m), "(Equal(m1m))")
}

1.4 時間戳

如何取時間戳:

package main
import (
	"fmt"
	"time"
)
func main() {
	now := time.Now()
	fmt.Println(now, "(當前時間)")
	// 取時間戳
	fmt.Println(now.Unix())       // 當前時間戳
	fmt.Println(now.UnixMilli())  // 毫秒級時間戳
	fmt.Println(now.UnixMicro())  // 微秒級時間戳
	fmt.Println(now.UnixNano())   // 納秒級時間戳
	fmt.Println(now.Nanosecond()) // 時間戳小數(shù)部分 單位:納秒
}

時間戳與時間的簡單轉(zhuǎn)換:

package main
import (
	"fmt"
	"time"
)
func main() {
	now := time.Now()
	fmt.Println(now, "(當前時間)")
	unix := now.Unix()
	fmt.Println(unix, "(秒級時間戳)")
	t := time.Unix(unix, 0)
	fmt.Println(t, "(原時間)")
	t = time.Unix(unix, 1) // 在時間戳的基礎(chǔ)上,加 1 納秒
	fmt.Println(t, "(加 1 納秒)")
	micro_unix := now.UnixMicro()
	fmt.Println(micro_unix, "(微秒級時間戳)")
	t1 := time.UnixMicro(micro_unix)
	fmt.Println(t1)
}

參考:

Golang中時間相關(guān)操作合集

Golang中時間格式化的實現(xiàn)詳解

一文帶你理解Golang中的Time結(jié)構(gòu)

二、dateparse 庫

dateparse 庫的作用主要就是將不同格式的字符串類型的時間,轉(zhuǎn)為 Time 時間類型。源碼地址:https://github.com/araddon/dateparse

根據(jù)本文 1.2.2 章節(jié)中第二部分 的轉(zhuǎn)換方法,并不能用于全部字符串日期的轉(zhuǎn)換,容易出現(xiàn)轉(zhuǎn)換失敗的情況。另外需要根據(jù)源日期的格式組織標準日期的格式,也會增加工作量。但是,當用上 dateparse 庫后,這一切將變的非常簡單。

dateparse 庫,就是將各種類型的日期格式字符串,轉(zhuǎn)換成同樣的格式,參考:2006-01-02 15:04:05 +0000 UTC。

具體引用的方法是func ParseLocal(datestr string, opts ...ParserOption) (time.Time, error){ },調(diào)用示例為Time_date_output := dateparse.ParseLocal(str_date_input)。

以下代碼是 github 上源碼中的示例,供參考:

package main
import (
	"flag"
	"fmt"
	"time"
	"github.com/scylladb/termtables"
	"github.com/araddon/dateparse"
)
var examples = []string{
	"May 8, 2009 5:57:51 PM",
	"oct 7, 1970",
	"oct 7, '70",
    ...
}
var (
	timezone = ""
)
func main() {
	flag.StringVar(&timezone, "timezone", "UTC", "Timezone aka `America/Los_Angeles` formatted time-zone")
	flag.Parse() // 取命令行參數(shù) timezone
	if timezone != "" {
		loc, err := time.LoadLocation(timezone)
		if err != nil {
			panic(err.Error())
		}
		time.Local = loc // 將默認的本地值修改為輸入的本地參數(shù)
	}
	table := termtables.CreateTable()
	table.AddHeaders("Input", "Parsed, and Output as %v")
	for _, dateExample := range examples { // 循環(huán)全部日期格式字符串,并輸出轉(zhuǎn)換后的格式
		t, err := dateparse.ParseLocal(dateExample)
		if err != nil {
			panic(err.Error())
		}
		table.AddRow(dateExample, fmt.Sprintf("%v", t))
	}
	fmt.Println(table.Render())
}
/*
+-------------------------------------------------------+-----------------------------------------+
| Input                                                 | Parsed, and Output as %v                |
+-------------------------------------------------------+-----------------------------------------+
| May 8, 2009 5:57:51 PM                                | 2009-05-08 17:57:51 +0000 UTC           |
| oct 7, 1970                                           | 1970-10-07 00:00:00 +0000 UTC           |
| oct 7, '70                                            | 1970-10-07 00:00:00 +0000 UTC           |
| oct. 7, 1970                                          | 1970-10-07 00:00:00 +0000 UTC           |
| oct. 7, 70                                            | 1970-10-07 00:00:00 +0000 UTC           |
| Mon Jan  2 15:04:05 2006                              | 2006-01-02 15:04:05 +0000 UTC           |
| Mon Jan  2 15:04:05 MST 2006                          | 2006-01-02 15:04:05 +0000 MST           |
| Mon Jan 02 15:04:05 -0700 2006                        | 2006-01-02 15:04:05 -0700 -0700         |
| Monday, 02-Jan-06 15:04:05 MST                        | 2006-01-02 15:04:05 +0000 MST           |
| Mon, 02 Jan 2006 15:04:05 MST                         | 2006-01-02 15:04:05 +0000 MST           |
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST)                | 2017-07-11 16:28:13 +0200 +0200         |
| Mon, 02 Jan 2006 15:04:05 -0700                       | 2006-01-02 15:04:05 -0700 -0700         |
| Mon 30 Sep 2018 09:09:09 PM UTC                       | 2018-09-30 21:09:09 +0000 UTC           |
| Mon Aug 10 15:44:11 UTC+0100 2015                     | 2015-08-10 15:44:11 +0000 UTC           |
| Thu, 4 Jan 2018 17:53:36 +0000                        | 2018-01-04 17:53:36 +0000 UTC           |
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT           |
| Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00)            | 2021-01-03 00:12:23 +0800 +0800         |
| September 17, 2012 10:09am                            | 2012-09-17 10:09:00 +0000 UTC           |
| September 17, 2012 at 10:09am PST-08                  | 2012-09-17 10:09:00 -0800 PST           |
| September 17, 2012, 10:10:09                          | 2012-09-17 10:10:09 +0000 UTC           |
| October 7, 1970                                       | 1970-10-07 00:00:00 +0000 UTC           |
| October 7th, 1970                                     | 1970-10-07 00:00:00 +0000 UTC           |
| 12 Feb 2006, 19:17                                    | 2006-02-12 19:17:00 +0000 UTC           |
| 12 Feb 2006 19:17                                     | 2006-02-12 19:17:00 +0000 UTC           |
| 14 May 2019 19:11:40.164                              | 2019-05-14 19:11:40.164 +0000 UTC       |
| 7 oct 70                                              | 1970-10-07 00:00:00 +0000 UTC           |
| 7 oct 1970                                            | 1970-10-07 00:00:00 +0000 UTC           |
| 03 February 2013                                      | 2013-02-03 00:00:00 +0000 UTC           |
| 1 July 2013                                           | 2013-07-01 00:00:00 +0000 UTC           |
| 2013-Feb-03                                           | 2013-02-03 00:00:00 +0000 UTC           |
| 06/Jan/2008:15:04:05 -0700                            | 2008-01-06 15:04:05 -0700 -0700         |
| 06/Jan/2008 15:04:05 -0700                            | 2008-01-06 15:04:05 -0700 -0700         |
| 3/31/2014                                             | 2014-03-31 00:00:00 +0000 UTC           |
| 03/31/2014                                            | 2014-03-31 00:00:00 +0000 UTC           |
| 08/21/71                                              | 1971-08-21 00:00:00 +0000 UTC           |
| 8/1/71                                                | 1971-08-01 00:00:00 +0000 UTC           |
| 4/8/2014 22:05                                        | 2014-04-08 22:05:00 +0000 UTC           |
| 04/08/2014 22:05                                      | 2014-04-08 22:05:00 +0000 UTC           |
| 4/8/14 22:05                                          | 2014-04-08 22:05:00 +0000 UTC           |
| 04/2/2014 03:00:51                                    | 2014-04-02 03:00:51 +0000 UTC           |
| 8/8/1965 12:00:00 AM                                  | 1965-08-08 00:00:00 +0000 UTC           |
| 8/8/1965 01:00:01 PM                                  | 1965-08-08 13:00:01 +0000 UTC           |
| 8/8/1965 01:00 PM                                     | 1965-08-08 13:00:00 +0000 UTC           |
| 8/8/1965 1:00 PM                                      | 1965-08-08 13:00:00 +0000 UTC           |
| 8/8/1965 12:00 AM                                     | 1965-08-08 00:00:00 +0000 UTC           |
| 4/02/2014 03:00:51                                    | 2014-04-02 03:00:51 +0000 UTC           |
| 03/19/2012 10:11:59                                   | 2012-03-19 10:11:59 +0000 UTC           |
| 03/19/2012 10:11:59.3186369                           | 2012-03-19 10:11:59.3186369 +0000 UTC   |
| 2014/3/31                                             | 2014-03-31 00:00:00 +0000 UTC           |
| 2014/03/31                                            | 2014-03-31 00:00:00 +0000 UTC           |
| 2014/4/8 22:05                                        | 2014-04-08 22:05:00 +0000 UTC           |
| 2014/04/08 22:05                                      | 2014-04-08 22:05:00 +0000 UTC           |
| 2014/04/2 03:00:51                                    | 2014-04-02 03:00:51 +0000 UTC           |
| 2014/4/02 03:00:51                                    | 2014-04-02 03:00:51 +0000 UTC           |
| 2012/03/19 10:11:59                                   | 2012-03-19 10:11:59 +0000 UTC           |
| 2012/03/19 10:11:59.3186369                           | 2012-03-19 10:11:59.3186369 +0000 UTC   |
| 2014:3:31                                             | 2014-03-31 00:00:00 +0000 UTC           |
| 2014:03:31                                            | 2014-03-31 00:00:00 +0000 UTC           |
| 2014:4:8 22:05                                        | 2014-04-08 22:05:00 +0000 UTC           |
| 2014:04:08 22:05                                      | 2014-04-08 22:05:00 +0000 UTC           |
| 2014:04:2 03:00:51                                    | 2014-04-02 03:00:51 +0000 UTC           |
| 2014:4:02 03:00:51                                    | 2014-04-02 03:00:51 +0000 UTC           |
| 2012:03:19 10:11:59                                   | 2012-03-19 10:11:59 +0000 UTC           |
| 2012:03:19 10:11:59.3186369                           | 2012-03-19 10:11:59.3186369 +0000 UTC   |
| 2014年04月08日                                        | 2014-04-08 00:00:00 +0000 UTC           |
| 2006-01-02T15:04:05+0000                              | 2006-01-02 15:04:05 +0000 UTC           |
| 2009-08-12T22:15:09-07:00                             | 2009-08-12 22:15:09 -0700 -0700         |
| 2009-08-12T22:15:09                                   | 2009-08-12 22:15:09 +0000 UTC           |
| 2009-08-12T22:15:09.988                               | 2009-08-12 22:15:09.988 +0000 UTC       |
| 2009-08-12T22:15:09Z                                  | 2009-08-12 22:15:09 +0000 UTC           |
| 2017-07-19T03:21:51:897+0100                          | 2017-07-19 03:21:51.897 +0100 +0100     |
| 2019-05-29T08:41-04                                   | 2019-05-29 08:41:00 -0400 -0400         |
| 2014-04-26 17:24:37.3186369                           | 2014-04-26 17:24:37.3186369 +0000 UTC   |
| 2012-08-03 18:31:59.257000000                         | 2012-08-03 18:31:59.257 +0000 UTC       |
| 2014-04-26 17:24:37.123                               | 2014-04-26 17:24:37.123 +0000 UTC       |
| 2013-04-01 22:43                                      | 2013-04-01 22:43:00 +0000 UTC           |
| 2013-04-01 22:43:22                                   | 2013-04-01 22:43:22 +0000 UTC           |
| 2014-12-16 06:20:00 UTC                               | 2014-12-16 06:20:00 +0000 UTC           |
| 2014-12-16 06:20:00 GMT                               | 2014-12-16 06:20:00 +0000 UTC           |
| 2014-04-26 05:24:37 PM                                | 2014-04-26 17:24:37 +0000 UTC           |
| 2014-04-26 13:13:43 +0800                             | 2014-04-26 13:13:43 +0800 +0800         |
| 2014-04-26 13:13:43 +0800 +08                         | 2014-04-26 13:13:43 +0800 +0800         |
| 2014-04-26 13:13:44 +09:00                            | 2014-04-26 13:13:44 +0900 +0900         |
| 2012-08-03 18:31:59.257000000 +0000 UTC               | 2012-08-03 18:31:59.257 +0000 UTC       |
| 2015-09-30 18:48:56.35272715 +0000 UTC                | 2015-09-30 18:48:56.35272715 +0000 UTC  |
| 2015-02-18 00:12:00 +0000 GMT                         | 2015-02-18 00:12:00 +0000 UTC           |
| 2015-02-18 00:12:00 +0000 UTC                         | 2015-02-18 00:12:00 +0000 UTC           |
| 2015-02-08 03:02:00 +0300 MSK m=+0.000000001          | 2015-02-08 03:02:00 +0300 +0300         |
| 2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001      | 2015-02-08 03:02:00.001 +0300 +0300     |
| 2017-07-19 03:21:51+00:00                             | 2017-07-19 03:21:51 +0000 UTC           |
| 2014-04-26                                            | 2014-04-26 00:00:00 +0000 UTC           |
| 2014-04                                               | 2014-04-01 00:00:00 +0000 UTC           |
| 2014                                                  | 2014-01-01 00:00:00 +0000 UTC           |
| 2014-05-11 08:20:13,787                               | 2014-05-11 08:20:13.787 +0000 UTC       |
| 2020-07-20+08:00                                      | 2020-07-20 00:00:00 +0800 +0800         |
| 3.31.2014                                             | 2014-03-31 00:00:00 +0000 UTC           |
| 03.31.2014                                            | 2014-03-31 00:00:00 +0000 UTC           |
| 08.21.71                                              | 1971-08-21 00:00:00 +0000 UTC           |
| 2014.03                                               | 2014-03-01 00:00:00 +0000 UTC           |
| 2014.03.30                                            | 2014-03-30 00:00:00 +0000 UTC           |
| 20140601                                              | 2014-06-01 00:00:00 +0000 UTC           |
| 20140722105203                                        | 2014-07-22 10:52:03 +0000 UTC           |
| 171113 14:14:20                                       | 2017-11-13 14:14:20 +0000 UTC           |
| 1332151919                                            | 2012-03-19 10:11:59 +0000 UTC           |
| 1384216367189                                         | 2013-11-12 00:32:47.189 +0000 UTC       |
| 1384216367111222                                      | 2013-11-12 00:32:47.111222 +0000 UTC    |
| 1384216367111222333                                   | 2013-11-12 00:32:47.111222333 +0000 UTC |
+-------------------------------------------------------+-----------------------------------------+
*/

以上就是GO中的時間操作總結(jié)(time&dateparse)的詳細內(nèi)容,更多關(guān)于GO時間操作的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Go Vendor 使用指南

    Go Vendor 使用指南

    govendor是一個基于vendor目錄機制的包管理工具,本文就來詳細的介紹一下Go Vendor 使用指南,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2026-04-04
  • go?micro微服務proto開發(fā)安裝及使用規(guī)則

    go?micro微服務proto開發(fā)安裝及使用規(guī)則

    這篇文章主要為大家介紹了go?micro微服務proto開發(fā)中安裝Protobuf及基本規(guī)范字段的規(guī)則詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • 深入了解Go語言的基本語法與常用函數(shù)

    深入了解Go語言的基本語法與常用函數(shù)

    這篇文章主要為大家詳細介紹一下Go語言中的基本語法與常用函數(shù),文中的示例代碼講解詳細,對我們學習Go語言有一定的幫助,需要的可以參考一下
    2022-07-07
  • 淺談golang package中init方法的多處定義及運行順序問題

    淺談golang package中init方法的多處定義及運行順序問題

    這篇文章主要介紹了淺談golang package中init方法的多處定義及運行順序問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-05-05
  • 詳解如何在Golang中執(zhí)行shell命令

    詳解如何在Golang中執(zhí)行shell命令

    這篇文章主要為大家詳細介紹了在 golang 中執(zhí)行 shell 命令的多種方法和場景,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-02-02
  • Go語言單元測試基礎(chǔ)從入門到放棄

    Go語言單元測試基礎(chǔ)從入門到放棄

    這篇文章主要介紹了Go單元測試基礎(chǔ)從入門到放棄為大家開啟Go語言單元測試第一篇章,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • golang使用mapstructure解析json

    golang使用mapstructure解析json

    mapstructure?是一個?Go?庫,用于將通用映射值解碼為結(jié)構(gòu),這篇文章主要來和大家介紹一下golang如何使用mapstructure解析json,需要的可以參考下
    2023-12-12
  • golang結(jié)構(gòu)化日志log/slog包之slog.Record的用法簡介

    golang結(jié)構(gòu)化日志log/slog包之slog.Record的用法簡介

    這篇文章主要為大家詳細介紹了golang結(jié)構(gòu)化日志log/slog包中slog.Record結(jié)構(gòu)體的使用方法和需要注意的點,文中的示例代碼講解詳細,需要的可以學習一下
    2023-10-10
  • Golang 拷貝Array或Slice的操作

    Golang 拷貝Array或Slice的操作

    這篇文章主要介紹了Golang 拷貝Array或Slice的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • golang操作rocketmq的示例代碼

    golang操作rocketmq的示例代碼

    這篇文章主要介紹了golang操作rocketmq的示例代碼,代碼簡單易懂,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04

最新評論

阿合奇县| 白山市| 公安县| 东平县| 达日县| 内江市| 观塘区| 通榆县| 剑川县| 陵水| 渑池县| 郸城县| 会东县| 汕尾市| 盘山县| 大邑县| 牙克石市| 广饶县| 大洼县| 亳州市| 鹤庆县| 泾源县| 松原市| 老河口市| 苏州市| 莱阳市| 罗定市| 高尔夫| 天祝| 汉沽区| 偏关县| 科技| 环江| 阜新| 板桥市| 通道| 日喀则市| 竹北市| 天水市| 民乐县| 花垣县|