Operating systems provide both a “wall clock,” which is subject to changes for clock synchronization, and a “monotonic clock,” which is not. The general rule is that the wall clock is for telling time and the monotonic clock is for measuring time. Rather than split the API, in this package the Time returned by time.Now contains both a wall clock reading and a monotonic clock reading; later time-telling operations use the wall clock reading, but later time-measuring operations, specifically comparisons and subtractions, use the monotonic clock reading.

操作系统提供两种时间:wall clock(墙上时间,用于时间同步,显示时间)和monotonic clock(单调时间,用于比较,测量时间)。time.Now()返回两种时间(clock和monotonic)分别用于显示和测量。


type Time struct{} // A Time represents an instant in time with nanosecond precision.


A Time represents an instant in time with nanosecond precision.

Programs using times should typically store and pass them as values, not pointers. That is, time variables and struct fields should be of type time.Time, not *time.Time.

Time零值代表时间点January 1, year 1, 00:00:00.000000000 UTC。

now := time.Now() time.Now().Day() time.Now().Minute() time.Now().Month()

type Duration int64 // 表示一段时间间隔,单位纳秒,可表示的最长时间大约290年。

type Location struct{}

type Month int

t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)

Date panics if loc is nil.

func Now() Time

func (t Time) Unix() int64 //Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.



A Ticker holds a channel that delivers “ticks” of a clock at intervals.


The Timer type represents a single event. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or AfterFunc.


Original: https://www.cnblogs.com/embedded-linux/p/13669343.html
Author: yuxi_o
Title: golang之time





最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总