timeutil

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const DateLayout = "2006-01-02"
View Source
const DateLayout2 = "2006.01.02"
View Source
const DateLayout3 = "20060102"
View Source
const DateLayout4 = "2006/01/02"
View Source
const DateLayout5 = "02/01/2006"

DateLayout5 "02/01/2006" 这个格式是有歧义的。 根据 Go 的解析规则,它代表 日/月/年。 但在美国,这个格式通常表示 月/日/年。

View Source
const DefaultLayout = "2006-01-02 15:04:05"

DefaultLayout 定义了最常用的时间格式

View Source
const DefaultLayout2 = "2006/01/02 15:04:05"
View Source
const DefaultLayout3 = "20060102150405"
View Source
const OnlyHourMinute = "15:04"
View Source
const OnlyTime = "15:04:05"

Variables

This section is empty.

Functions

func DayEnd

func DayEnd(t time.Time) time.Time

DayEnd 某一天 23:59:59.999999999

func DayStart

func DayStart(t time.Time) time.Time

DayStart 某一天零点

func Format

func Format(t time.Time) string

Format 将 time.Time 格式化为 "2006-01-02 15:04:05" 格式

func FormatWithLayout

func FormatWithLayout(t time.Time, layout string) string

FormatWithLayout 自定义格式的format为字符串

func FromMillis

func FromMillis(msec int64) time.Time

FromMillis 将毫秒级时间戳转换为 time.Time (使用本地时区)

func FromSeconds

func FromSeconds(sec int64) time.Time

FromSeconds 将秒级时间戳转换为 time.Time (使用本地时区)

func LastYearEnd

func LastYearEnd() time.Time

func LastYearStart

func LastYearStart() time.Time

func MonthEnd

func MonthEnd(t time.Time) time.Time

MonthEnd 某月最后一天 23:59:59.999999999

func MonthStart

func MonthStart(t time.Time) time.Time

MonthStart 某月第一天零点

func NowMicro

func NowMicro() int64

NowMicro 微秒级时间戳 (int64)

func NowMillis

func NowMillis() int64

NowMillis 毫秒级时间戳 (int64)

func NowNanos

func NowNanos() int64

NowNanos 纳秒级时间戳 (int64)

func NowSeconds

func NowSeconds() int64

NowSeconds 秒级时间戳 (int64)

func ParseString

func ParseString(layout, value string) (time.Time, error)

ParseString 使用指定的布局和本地时区解析时间字符串

func ParseStringAuto

func ParseStringAuto(value string) (time.Time, error)

ParseStringAuto 自动尝试多种常见格式来解析时间字符串 (使用本地时区)

func ThisMonthEnd

func ThisMonthEnd() time.Time

func ThisMonthStart

func ThisMonthStart() time.Time

func ThisWeekEnd

func ThisWeekEnd() time.Time

func ThisWeekStart

func ThisWeekStart() time.Time

func ThisYearEnd

func ThisYearEnd() time.Time

func ThisYearStart

func ThisYearStart() time.Time

func TodayEnd

func TodayEnd() time.Time

func TodayStart

func TodayStart() time.Time

func TomorrowEnd

func TomorrowEnd() time.Time

func TomorrowStart

func TomorrowStart() time.Time

func WeekEnd

func WeekEnd(t time.Time) time.Time

WeekEnd 获取指定时间所在周的结束时间 (周日, 23:59:59...)

func WeekStart

func WeekStart(t time.Time) time.Time

WeekStart 获取指定时间所在周的开始时间 (周一, 00:00:00)

func YearEnd

func YearEnd(t time.Time) time.Time

YearEnd 某年12月31日 23:59:59.999999999

func YearStart

func YearStart(t time.Time) time.Time

YearStart 某年1月1日零点

func YesterdayEnd

func YesterdayEnd() time.Time

func YesterdayStart

func YesterdayStart() time.Time

Types

This section is empty.

Jump to

Keyboard shortcuts

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