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

相关文章
相关标签/搜索