GO_TIME
time包下的几个结构体
time.Time
表示一个时间点
type Time struct {
sec int64 // 从1年1月1日 00:00:00 UTC 至今过去的秒数
nsec int32 // 最近一秒到下一秒过去的纳秒数
loc *Location // 时区
}
方法
func (t Time) UTC() Time {}// 获取指定时间在UTC 时区的时间表示func (t Time) Local() Time {}// 以本地时区表示func (t Time) In(loc *Location) Time {}// 时间在指定时区的表示func (t Time) Format(layout string) string {}// 按指定格式显示时间
t4 := time.Now();
fmt.Println(t4.Format("2006-01-02 15:04:05"));
func (t Time) Date() (year int, month Month, day int) {}// 返回时间的日期信息func (t Time) Year() int {}// 返回年func (t Time) Month() Month {}// 月func (t Time) Day() int {}// 日func (t Time) Weekday() Weekday {}// 星期func (t Time) ISOWeek() (year, week int) {}// 返回年,星期范围编号func (t Time) Clock() (hour, min, sec int) {}// 返回时间的时分秒func (t Time) Hour() int {}// 返回小时func (t Time) Minute() int {}// 分钟func (t Time) Second() int {}// 秒func (t Time) Nanosecond() int {}// 纳秒func (t Time) YearDay() int {}// 一年中对应的天func (t Time) Location() *Location {}// 时间的时区func (t Time) Zone() (name string, offset int) {}// 时间所在时区的规范名和想对UTC 时间偏移量func (t Time) Unix() int64 {}// 时间转为时间戳func (t Time) UnixNano() int64 {}// 时间转为时间戳(纳秒)
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-ufunc (t Time) AddDate(years int, months int, days int) Time {}返回增加了给出的年份、月份和天数的时间点Time
time.Month 表示某一月
type Month int
相关常量
const (
January Month = 1 + iota
February
March
April
May
June
July
August
September
October
November
December
)
time.Weekday 代表一周的第几
type Weekday int
相关常量
const (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
time.Duration 时间段
type Duration int64
相关常量
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond // 纳秒
Millisecond = 1000 * Microsecond // 微秒
Second = 1000 * Millisecond // 秒
Minute = 60 * Second // 分钟
Hour = 60 * Minute // 小时
)
包中函数
func Now() Time {}// 当前本地时间func Unix(sec int64, nsec int64) Time {}// 根据时间戳返回本地时间func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time {}// 返回指定时间
// 当前本地时间
t = time.Now()
fmt.Println("'time.Now': ", t)
// 根据时间戳返回本地时间
t_by_unix := time.Unix(1487780010, 0)
fmt.Println("'time.Unix': ", t_by_unix)
// 返回指定时间
t_by_date := time.Date(2017, time.Month(2), 23, 1, 30, 30, 0, l)
fmt.Println("'time.Date': ", t_by_date)
func Sleep(d Duration)// Sleep阻塞当前go程至少d代表的时间段。d<=0时,Sleep会立刻返回

浙公网安备 33010602011771号