go time類操做

fmt.Println(time.Now().Format("2006-01-02 15:04:05")) # 這是個奇葩,必須是這個時間點, 聽說是go誕生之日, 記憶方法:6-1-2-3-4-5
# 2014-01-07 09:42:20

獲取當前時間:time.Now()。返回time對象ide

獲取當前時間戳:time.Now().Unix()orm

1、轉time對象對象

1. 時間戳整數轉time,Unix():time.Unix(time.Now().Unix(),0)字符串

// Unix returns the local Time corresponding to the given Unix time,
// sec seconds and nsec nanoseconds since January 1, 1970 UTC.
// It is valid to pass nsec outside the range [0, 999999999].
// Not all sec values have a corresponding time value. One such
// value is 1<<63-1 (the largest int64 value).
func Unix(sec int64, nsec int64) Time {

2.字符串轉time,Parse():time.Parse("20060102","20180328")string

func Parse(layout, value string) (Time, error) {

2、time對象轉其它class

1. time轉時間戳整數,Unix(): time.Now().Unix()方法

2.time轉格式化的時間,Format:time.Now().Format("20060102")im

相關文章
相關標籤/搜索