go语言中time包

107 阅读1分钟
time.Time

type Time struct {
    wall unit64   // 当前时间秒数
    ext  int64    // 当前时间纳秒数
    loc  *Location  // 时区信息
}
time.Duration

// Duration 表示两个时间之间的纳秒数

type Duration int64
time.Location

type Location struct {
    name        string
    zone        []zone
    tx          []zoneTrans
    extend      string
    cacheStart  int64
    cacheEnd    int64
    cacheZone   *zone
}

// A zone represents a single time zone such as CET.
type zone struct {
	name   string // abbreviated name, "CET"
	offset int    // seconds east of UTC
	isDST  bool   // is this zone Daylight Savings Time?
}

// A zoneTrans represents a single time zone transition.
type zoneTrans struct {
	when         int64 // transition time, in seconds since 1970 GMT
	index        uint8 // the index of the zone that goes into effect at that time
	isstd, isutc bool  // ignored - no idea what these mean
}
time.Month

// 表示一年的第几个月(January = 1, ...)

type Month int
time.Ticker

// Ticker是一个周期触发定时的计时器,它会按照一个时间间隔把当前时间保存到C

type Ticker struct {
   C <-chan Time 
   r runtimeTimer
}
time.ParseError

// 当解析一个时间字符串错误时用ParseError表示

type ParseError struct {
   Layout     string
   Value      string
   LayoutElem string
   ValueElem  string
   Message    string
}

time.Timer

// Timer类型表示一个事件
// 当Timer超时时,会将当前时间保存到C,除非这个Timer是被AfterFunc创建的
// Timer实例必须由NewTimer和AfterFunc创建

type Timer struct {
   C <-chan Time  // 只读通道,通道里面保存的Time类型数据
   r runtimeTimer
}
time.Weekday

// Weekday表示一周的第几天(Sunday = 0, ...)

type Weekday int
timestamppb.Timestamp{}

// timestamp.proto中定义的一个消息

message Timestamp {
  int64 seconds = 1;  // 表示自Unix元年(1970-01-01T00:00:00Z)开始的秒数

  int32 nanos = 2;
}