xtime

package
v2.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 5 Imported by: 20

Documentation

Index

Constants

View Source
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"
)
View Source
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

func GetLocation() *time.Location

GetLocation 获取当前时间区域 @return @1 *time.Location 当前使用的时间区域

func IsLeapYear added in v2.3.3

func IsLeapYear(year int) bool

IsLeapYear 是否是闰年 @param year int 年份 @return @1 bool 是否为闰年

func SetLocation added in v2.5.3

func SetLocation(loc *time.Location)

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

type Time = time.Time

Time 标准时间类型别名

func Day added in v2.1.0

func Day(offset ...int) Time

Day 获取某一天的当前时刻 @param offset ...int 偏移天数,例如:-1:前一天 0:当前 1:明天 @return @1 Time 偏移后的时间

func DayHead added in v2.1.0

func DayHead(offset ...int) Time

DayHead 获取一天中的第一秒 @param offset ...int 偏移天数,例如:-1:前一天 0:当前 1:明天 @return @1 Time 当天第一秒

func DayTail added in v2.1.0

func DayTail(offset ...int) Time

DayTail 获取一天中的最后一秒 @param offset ...int 偏移天数,例如:-1:前一天 0:当前 1:明天 @return @1 Time 当天最后一秒

func Month added in v2.1.0

func Month(offset ...int) Time

Month 获取某一月的当前时刻 @param offset ...int 偏移月数,例如:-1:前一月 0:当前月 1:下一月 @return @1 Time 偏移后的时间

func MonthHead added in v2.1.0

func MonthHead(offset ...int) Time

MonthHead 获取一月中的第一天的第一秒 @param offset ...int 偏移月数,例如:-1:前一月 0:当前月 1:下一月 @return @1 Time 目标月第一天第一秒

func MonthTail added in v2.1.0

func MonthTail(offset ...int) Time

MonthTail 获取一月中的最后一天的最后一秒 @param offset ...int 偏移月数,例如:-1:前一月 0:当前月 1:下一月 @return @1 Time 目标月最后一天最后一秒

func Now

func Now() Time

Now 当前时间 @return @1 Time 当前时间(使用当前时区)

func Parse added in v2.1.0

func Parse(layout string, value string) (Time, error)

Parse 解析日期时间字符串 使用当前时区按指定布局解析日期时间 @param layout string 时间布局 @param value string 待解析的日期时间字符串 @return @1 Time 解析后的时间 @return @2 error 解析错误

func Today

func Today() Time

Today 今天 @return @1 Time 当前时间

func Tomorrow

func Tomorrow() Time

Tomorrow 明天 @return @1 Time 明天的当前时刻

func Unix

func Unix(sec int64, nsec ...int64) Time

Unix 时间戳转标准时间 @param sec int64 秒级时间戳 @param nsec ...int64 可选,纳秒部分 @return @1 Time 转换后的标准时间

func UnixMicro

func UnixMicro(usec int64) Time

UnixMicro 时间戳(微秒)转标准时间 @param usec int64 微秒级时间戳 @return @1 Time 转换后的标准时间

func UnixMilli

func UnixMilli(msec int64) Time

UnixMilli 时间戳(毫秒)转标准时间 @param msec int64 毫秒级时间戳 @return @1 Time 转换后的标准时间

func UnixNano

func UnixNano(nsec int64) Time

UnixNano 时间戳(纳秒)转标准时间 @param nsec int64 纳秒级时间戳 @return @1 Time 转换后的标准时间

func Week added in v2.1.0

func Week(offset ...int) Time

Week 获取一周中的当前时刻 @param offset ...int 偏移周数,例如:-1:上一周 0:本周 1:下一周 @return @1 Time 偏移后的时间

func WeekHead added in v2.1.0

func WeekHead(offset ...int) Time

WeekHead 获取一周中的第一天的第一秒(以周一为一周第一天) @param offset ...int 偏移周数,例如:-1:上一周 0:本周 1:下一周 @return @1 Time 目标周的周一第一秒

func WeekTail added in v2.1.0

func WeekTail(offset ...int) Time

WeekTail 获取一周中的最后一天的最后一秒(以周日为一周最后一天) @param offset ...int 偏移周数,例如:-1:上一周 0:本周 1:下一周 @return @1 Time 目标周的周日最后一秒

func Yesterday

func Yesterday() Time

Yesterday 昨天 @return @1 Time 昨天的当前时刻

type TransformRule

type TransformRule struct {
	Max       uint   // 时间上限(秒),0 表示无上限
	PastTpl   string // 过去时间的显示模板
	FutureTpl string // 未来时间的显示模板
}

TransformRule 时间转换规则

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL