timeutil

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 定義常用的時間格式
	FormatDateOnly       = "2006-01-02"
	FormatTimeOnly       = "15:04:05"
	FormatDateTime       = "2006-01-02 15:04:05"
	FormatISO8601        = "2006-01-02T15:04:05Z07:00"
	FormatISO8601Compact = "20060102T150405Z0700"
	FormatRFC1123        = time.RFC1123
	FormatRFC822         = time.RFC822
)

Variables

This section is empty.

Functions

func DaysBetween

func DaysBetween(startDate, endDate time.Time) int

DaysBetween 函數,計算兩個日期之間的天數,返回值為正數

func DaysDiff added in v0.6.2

func DaysDiff(startDate, endDate time.Time) int

DaysDiff 函數,計算兩個日期之間的天數,不取絕對值

func FormatTime

func FormatTime(t time.Time, format string) string

FormatTime 格式化指定時間

func MonthsBetween added in v0.6.2

func MonthsBetween(startDate, endDate time.Time) int

MonthsBetween 函數,計算兩個日期之間的月份數,返回值為正數

func MonthsDiff added in v0.6.2

func MonthsDiff(startDate, endDate time.Time) int

MonthsDiff 函數,計算兩個日期之間的月份數,不取絕對值

func NowFormatted

func NowFormatted(format string, timezoneOffset ...int) string

NowFormatted 根據指定格式返回當前時間的字串表示,預設使用 UTC+0

func TimeInZone

func TimeInZone(offsetHours int) time.Time

TimeInZone 函數,接受一個 UTC 偏移值,返回該時區的當下時間

func UnixAfterSeconds added in v0.6.3

func UnixAfterSeconds(seconds int) int64

UnixAfterSeconds 函數,接受一個秒數值,返回當前時間加上該秒數後的 Unix 時間戳 接受 0 和負值,如果是負值,則表示計算幾秒前的 Unix 時間戳

func YearsBetween added in v0.6.2

func YearsBetween(startDate, endDate time.Time) int

YearsBetween 函數,計算兩個日期之間的年數,返回值為正數

func YearsDiff added in v0.6.2

func YearsDiff(startDate, endDate time.Time) int

YearsDiff 函數,計算兩個日期之間的年數,不取絕對值

Types

This section is empty.

Jump to

Keyboard shortcuts

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