一.导入包
import "time"
@H_502_5@
二.转换成Time对象
三.Time对象的方法
年月日周
- Date() : 返回时间的日期信息
返回值int类型
- Year() : 返回年
返回值int类型
- Month () : 返回月
返回值Month类型
- Day () : 返回日
返回值int类型
- YearDay() : 一年中对应的天
返回值int类型
年,星期范围编号
- ISOWeek () : 返回年,星期范围编号
int类型
时分秒
-
Clock () : 返回 时分秒
返回值int类型
@H_502_5@ -
Hour () : 返回时
返回值int类型
@H_502_5@ -
Minute () : 返回分
返回值int类型
@H_502_5@ -
Second () : 返回秒
返回值int类型
@H_502_5@ -
Nanosecond () : 返回纳秒
返回值int类型
@H_502_5@
时间戳
- Unix() :时间戳
返回值 int64
- UnixNano() :时间戳(纳秒)
返回值 int64
时区
- Location ():时区
返回值 *Location
- Zone() :时区偏差
返回值string+int
四.时间序列化和返序列化以及比较与计算
参考https://www.jianshu.com/p/9d5636d34f17
@H_502_5@
列化和返序列化
func (t Time) MarshalBinary() ([]byte,error) {}
// 时间序列化@H_502_5@
func (t Time) UnmarshalBinary(data []byte) error {}
// 反序列化@H_502_5@
func (t Time) MarshalJSON() ([]byte,error) {}
// 时间序列化@H_502_5@
func (t Time) MarshalText() ([]byte,error) {}
// 时间序列化@H_502_5@
func (t Time) GobEncode() ([]byte,error) {}
// 时间序列化@H_502_5@
func (t Time) GobDecode() ([]byte,error) {}
// 时间序列化@H_502_5@
比较与计算
func (t Time) IsZero() bool {}
// 是否是零时时间@H_502_5@
func (t Time) After(u Time) bool {}
// 时间在u 之前@H_502_5@
func (t Time) Before(u Time) bool {}
// 时间在u 之后@H_502_5@
func (t Time) Equal(u Time) bool {}
// 时间与u 相同@H_502_5@
func (t Time) Add(d Duration) Time {}
// 返回t +d 的时间点@H_502_5@
func (t Time) Sub(u Time) Duration {}
// 返回 t-u@H_502_5@
func (t Time) AddDate(years int,months int,days int) Time {}
返回增加了给出的年份、月份和天@H_502_5@