datetime

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DatetimeLayout = "2006-01-02 15:04:05"
	ZeroDateStr    = "0001-01-01 00:00:00" // zero date
)

Variables

This section is empty.

Functions

func FormatDate

func FormatDate(date time.Time) string

FormatDate 使用 "2006-01-02 15:04:05" 格式化日期

如果日期为 zero date(0001-01-01 00:00:00),返回 ""

func FormatDateWithLayout

func FormatDateWithLayout(date time.Time, layout string) string

FormatDateWithLayout 使用指定的 日期模版 格式化日期

如果日期为 zero date,返回 ""

func GetDayRange added in v1.19.0

func GetDayRange(date time.Time) (firstOfDay, lastOfDay time.Time)

GetDayRange 返回日开始(当天零点)和日结束(次日零点)

firstOfDay <= date < lastOfDay

func GetMonthRange added in v1.16.0

func GetMonthRange(date time.Time) (firstOfMonth, lastOfMonth time.Time)

GetMonthRange 返回月开始(本月第一天零点)和月结束(下月第一天零点)

firstOfMonth <= date < lastOfMonth

func GetWeekRange added in v1.16.0

func GetWeekRange(date time.Time, firstDayOfWeek time.Weekday) (firstOfWeek, lastOfWeek time.Time)

GetWeekRange firstDayOfWeek 用于指定每周的第一天,返回周开始(本周第一天零点)和周结束(下一周第一天零点)

firstOfWeek <= date < lastOfWeek

func GetYearRange added in v1.19.0

func GetYearRange(date time.Time) (firstOfYear, lastOfYear time.Time)

GetYearRange 返回年开始(本年第一天零点)和年结束(下年第一天零点)

firstOfYear <= date < lastOfYear

func ParseDate

func ParseDate(val any) (result time.Time)

ParseDate 使用 "2006-01-02 15:04:05" 解析日期

如果解析失败,返回 time.Time{}

func ParseDateRFC3339Nano

func ParseDateRFC3339Nano(val any) (result time.Time)

ParseDateRFC3339Nano 使用 RFC3339Nano 解析日期

如果解析失败,返回 time.Time{}

func ParseDateWithLayout

func ParseDateWithLayout(val any, layout string) (result time.Time)

ParseDateWithLayout 使用指定的 日期模版 解析日期

如果解析失败,返回 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