time

constants

const:

1
2
3
4
5
6
const (
    ANSIC       = "Mon Jan _2 15:04:05 2006"
    Unixdate    = "Mon Jan _2 15:04:05 MST 2006"
    RFC3339     = "2006-01-02T15:04:05Z07:00"
    ...
)

functions

1
2
3
4
5
6
// 阻塞go程d代表的时间段
func Sleep(d Duration)

func After(d Duration) <- chan Time

func Tick(d Duration) <- chan Time

Time

代表一个纳秒精度的时间点.

零值是January 1, year 1, 00:00:00.000000000 UTC.

struct:

1
type  Time struct {}

functions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// 格式化一个时间, eg: 2009-11-10 15:00:00 -0800 PST
func date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time

// 返回当前本地时间, eg: 2018-03-18 12:16:55.842029 +0800 CST m=+0.001962301
func Now() Time

func Parse(layout, value s tring) (Time, error)

func ParseInLocation(layout, value string, loc *Location) (Time, error)

func Unix(sec int64, nsec int64) Time

methods:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 返回T的地点和时区信息
func (t Time) Location() *Location

// 返回t的时区规范名和相对于UTC的偏移量
func (t Time) Zone() (name string, offset int)

func (t Time) IsZero() bool

func (t Time) Local() Time

func (t Time) UTC() Time

func (t Time) In(loc *Location) Time

func (t Time) Unix() int64

func (t Time) UnixNano() int64

// 比较两个时间
func (t Time) Equal(u Time) bool

// t > u 返回true
func (t Time) Before(u Time) bool

// t < u 返回true
func (t Time) After(u Time) bool

// 返回t的年月日.
func (t Time) date() (year int, month Month, day int)

// 返回t对应的时分秒
func (t Time) Clock() (hour, min, sec int)

// 返回t对应的年
func (t Time) Year() int

// 返回t对应的月
func (t Time) Month() Month

func (t Time) ISOWeek() (year, week int)

// 返回t对应的当年的第几天
func (t Time) YearDay() int

// 返回t对应的当月的第几天
func (t Time) Day() int

// 返回t对应的星期几
func (t Time) Weekday() Weekday

// 返回t对应的第几小时
func (t Time) Hour() int

// 返回t对应的分钟
func (t Time) Minute() int

// 返回t对应的秒
func (t Time) Second() int

// 返回t对应的纳秒偏移量
func (t Time) Nanosecond() int

func (t Time) Add(d Duration) Time

func (t Time) Adddate(years int, months int, days int) Time

func (t Time) Sub(u Time) Duration

func (t Time) Round(d duration) Time

func (t Time) Truncate(d Duration) Time

func (t Time) Format(layout string) string

func (t Time) String(layout string) string

Weekday

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
type Weekday int

const (
    Sunday Weekday = iota
    Monday
    Tuesday
    Wednesday
    Thursday
    Friday
    Saturday
)

methods:

1
2
// 返回d对应的英文名
func (d Weekday) String() string

Month

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
type Month int

const (
    January Month = 1 + iota
    February
    March
    April
    May
    June
    July
    August
    September
    October
    November
    December
)

methods:

1
2
// 返回m对应的英文名
func (m Month) String() string

Location

struct:

1
type Location struct {}

functions:

1
2
3
4
5
6
7
8
// 返回使用给定名字创建的Location
// name == "" 或 name == "UTC", 返回UTC
// name == "Local", fanhui1Local
// 其它时间数据库的值
func LoadLocation(name string) (*Location, error)

// 使用给定的名称和偏移量创建一个Location
func FixedZone(name string, offset int) *Location

methods:

1
2
// 返回对时区信息的描述
func (l *Location) String() string

Duration

Timer

Ticker


container/heap


container/list


container/ring


compress/bzip2


compress/flate


compress/gzip


compress/lzw


compress/zlib


archive