datetime

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 1 Imported by: 0

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 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 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