Go time 模块

time.Duration 类型代表两个时间点之间经过的纳秒数,可表示的最长时间段约为290年。
func (t Time) In(loc *Location) Time {} // 时间在指定时区的表示
func (t Time) Format(layout string) string {} // 按指定格式显示时间
func (t Time) ISOWeek() (year, week int) {} // 返回年,星期范围编号
func (t Time) Clock() (hour, min, sec int) {} // 返回时间的时分秒
func (t Time) Zone() (name string, offset int) {} // 时间所在时区的规范名和想对UTC 时间偏移量
func (t Time) IsZero() bool {} // 是否是零时时间
func (t Time) After(u Time) bool {} // 时间在u 之前
func (t Time) Before(u Time) bool {} // 时间在u 之后
func (t Time) Equal(u Time) bool {} // 时间与u 相同
func (t Time) Add(d Duration) Time {} // 返回t +d 的时间点
func (t Time) Sub(u Time) Duration {} // 返回 t-u
func (t Time) AddDate(years int, months int, days int) Time {} 返回增加了给出的年份、月份和天数的时间点Time
func (t Time) MarshalBinary() ([]byte, error) {} // 时间序列化
func (t Time) UnmarshalBinary(data []byte) error {} // 反序列化
func (t Time) MarshalJSON() ([]byte, error) {} // 时间序列化
func (t Time) MarshalText() ([]byte, error) {} // 时间序列化
func (t Time) GobEncode() ([]byte, error) {} // 时间序列化
func (t Time) GobDecode() ([]byte, error) {} // 时间序列化

//tk := time.Tick(time.Second)   相当于阻塞 即:几秒执行一次代码, 可多次执行
//af := time.After(time.Second*3)  在多少秒之后执行一次,只执行一次

package main import (
"fmt" "time" ) func main() { tk := time.Tick(time.Second) af := time.After(time.Second*3) for { select { case <-tk: fmt.Println("tk" ) case <- af: fmt.Println("af") default: } } }

转载至:https://studygolang.com/articles/9567

邮箱: 1090055252@qq.com
原文地址:https://www.cnblogs.com/zhaoxianxin/p/14389531.html