Help us shape the future of Go! Take the 2026 Go Developer Survey

timex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package timex 提供常用的时间操作工具函数。

包含时间戳转换、日期格式化、时区处理等功能。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTimezone

func ConvertTimezone(datetime string, fromLoc string) (string, error)

ConvertTimezone 将日期时间从指定时区转换为本地时区。

func Date2Stamp

func Date2Stamp(date string, format string) int64

Date2Stamp 将日期字符串转换为 Unix 时间戳。 使用本地时区解析(time.ParseInLocation),避免 UTC 偏移问题。 解析失败时返回 0。

func GetCurrentDate

func GetCurrentDate(format string) string

GetCurrentDate 返回当前日期字符串,默认格式为 "2006-01-02"。

func GetCurrentDayStartTime

func GetCurrentDayStartTime() int64

GetCurrentDayStartTime 返回今天 00:00:00 的 Unix 时间戳。

func GetCurrentTime

func GetCurrentTime() int

GetCurrentTime 返回当前 Unix 时间戳。

func NDateBefore

func NDateBefore(n int, isMulti bool, format string) []string

NDateBefore 获取前 n 天的日期列表。 isMulti 为 true 时返回前 n 天每一天的日期,否则只返回第 n 天的日期。

func StampInt2Date

func StampInt2Date(timestamp int64, format string) string

StampInt2Date 将 Unix 时间戳转换为日期格式。

func StampString2Date

func StampString2Date(timestampStr, format string) string

StampString2Date 将时间戳字符串转换为日期格式。 解析失败时返回空字符串。

func TimestampString

func TimestampString() string

TimestampString 返回当前 Unix 时间戳的字符串。 时间戳始终为 UTC 秒数,不含时区偏移(Unix 时间戳是时区无关的)。

Types

This section is empty.

Directories

Path Synopsis
Package cron 提供 Cron 表达式解析和调度功能。
Package cron 提供 Cron 表达式解析和调度功能。

Jump to

Keyboard shortcuts

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