Documentation
¶
Index ¶
- Constants
- func GetLocation() *time.Location
- func IsLeapYear(year int) bool
- func SetLocation(loc *time.Location)
- func Transform(t Time, rule ...[]TransformRule) string
- type Time
- func Day(offset ...int) Time
- func DayHead(offset ...int) Time
- func DayTail(offset ...int) Time
- func Month(offset ...int) Time
- func MonthHead(offset ...int) Time
- func MonthTail(offset ...int) Time
- func Now() Time
- func Parse(layout string, value string) (Time, error)
- func Today() Time
- func Tomorrow() Time
- func Unix(sec int64, nsec ...int64) Time
- func UnixMicro(usec int64) Time
- func UnixMilli(msec int64) Time
- func UnixNano(nsec int64) Time
- func Week(offset ...int) Time
- func WeekHead(offset ...int) Time
- func WeekTail(offset ...int) Time
- func Yesterday() Time
- type TransformRule
Constants ¶
const ( Layout = time.Layout // The reference time, in numerical order. ANSIC = time.ANSIC UnixDate = time.UnixDate RubyDate = time.RubyDate RFC822 = time.RFC822 RFC822Z = time.RFC822Z RFC850 = time.RFC850 RFC1123 = time.RFC1123 RFC1123Z = time.RFC1123Z RFC3339 = time.RFC3339 RFC3339Nano = time.RFC3339Nano Kitchen = time.Kitchen Stamp = time.Stamp StampMilli = time.StampMilli StampMicro = time.StampMicro StampNano = time.StampNano DateTime = time.DateTime DateOnly = time.DateOnly TimeOnly = time.TimeOnly MonthOnly = "2006-01" YearOnly = "2006" )
const ( TimeFormat = "H:i:s" DateFormat = "Y-m-d" DatetimeFormat = "Y-m-d H:i:s" )
Variables ¶
This section is empty.
Functions ¶
func GetLocation ¶ added in v2.6.0
GetLocation 获取当前时间区域 @return @1 *time.Location 当前使用的时间区域
func IsLeapYear ¶ added in v2.3.3
IsLeapYear 是否是闰年 @param year int 年份 @return @1 bool 是否为闰年
func SetLocation ¶ added in v2.5.3
SetLocation 设置时间区域(线程安全) @param loc *time.Location 待设置的时间区域
func Transform ¶
func Transform(t Time, rule ...[]TransformRule) string
Transform 时间转换 @param t Time 目标时间 @param rule ...[]TransformRule 可选自定义转换规则 @return @1 string 转换后的时间描述
Types ¶
type Time ¶ added in v2.1.1
Time 标准时间类型别名
func Day ¶ added in v2.1.0
Day 获取某一天的当前时刻 @param offset ...int 偏移天数,例如:-1:前一天 0:当前 1:明天 @return @1 Time 偏移后的时间
func DayHead ¶ added in v2.1.0
DayHead 获取一天中的第一秒 @param offset ...int 偏移天数,例如:-1:前一天 0:当前 1:明天 @return @1 Time 当天第一秒
func DayTail ¶ added in v2.1.0
DayTail 获取一天中的最后一秒 @param offset ...int 偏移天数,例如:-1:前一天 0:当前 1:明天 @return @1 Time 当天最后一秒
func Month ¶ added in v2.1.0
Month 获取某一月的当前时刻 @param offset ...int 偏移月数,例如:-1:前一月 0:当前月 1:下一月 @return @1 Time 偏移后的时间
func MonthHead ¶ added in v2.1.0
MonthHead 获取一月中的第一天的第一秒 @param offset ...int 偏移月数,例如:-1:前一月 0:当前月 1:下一月 @return @1 Time 目标月第一天第一秒
func MonthTail ¶ added in v2.1.0
MonthTail 获取一月中的最后一天的最后一秒 @param offset ...int 偏移月数,例如:-1:前一月 0:当前月 1:下一月 @return @1 Time 目标月最后一天最后一秒
func Parse ¶ added in v2.1.0
Parse 解析日期时间字符串 使用当前时区按指定布局解析日期时间 @param layout string 时间布局 @param value string 待解析的日期时间字符串 @return @1 Time 解析后的时间 @return @2 error 解析错误
func Unix ¶
Unix 时间戳转标准时间 @param sec int64 秒级时间戳 @param nsec ...int64 可选,纳秒部分 @return @1 Time 转换后的标准时间
func Week ¶ added in v2.1.0
Week 获取一周中的当前时刻 @param offset ...int 偏移周数,例如:-1:上一周 0:本周 1:下一周 @return @1 Time 偏移后的时间
func WeekHead ¶ added in v2.1.0
WeekHead 获取一周中的第一天的第一秒(以周一为一周第一天) @param offset ...int 偏移周数,例如:-1:上一周 0:本周 1:下一周 @return @1 Time 目标周的周一第一秒
type TransformRule ¶
type TransformRule struct {
Max uint // 时间上限(秒),0 表示无上限
PastTpl string // 过去时间的显示模板
FutureTpl string // 未来时间的显示模板
}
TransformRule 时间转换规则