- common/tools 工具模块,10 个子功能:md5/cryptox/uuid/random/timex/convertx/strx/slicex/ip/filex(薄封装 GoFrame 内置组件) - AGENTS.md 项目智能体说明书(架构、规范、命令、记忆体系索引) - docs/change-log/2026-08-24.md 本次请求与变更记录 - .gitignore 排除 .workbuddy/;PROJECT_STRUCTURE.md 补充目录树
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// Package timex provides time formatting and computation helpers on top of gtime.
|
|
package timex
|
|
|
|
import (
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
)
|
|
|
|
const (
|
|
// LayoutDateTime is the conventional datetime layout: 2006-01-02 15:04:05.
|
|
LayoutDateTime = "2006-01-02 15:04:05"
|
|
// LayoutDate is the conventional date layout: 2006-01-02.
|
|
LayoutDate = "2006-01-02"
|
|
)
|
|
|
|
// Now returns the current time.
|
|
func Now() *gtime.Time {
|
|
return gtime.Now()
|
|
}
|
|
|
|
// Format returns t formatted with the given layout.
|
|
// When layout is empty, LayoutDateTime is used.
|
|
func Format(t *gtime.Time, layout ...string) string {
|
|
ly := LayoutDateTime
|
|
if len(layout) > 0 && layout[0] != "" {
|
|
ly = layout[0]
|
|
}
|
|
return t.Format(ly)
|
|
}
|
|
|
|
// Timestamp returns the current Unix timestamp in seconds.
|
|
func Timestamp() int64 {
|
|
return gtime.Now().Timestamp()
|
|
}
|
|
|
|
// StartOfDay returns the beginning (00:00:00) of the day containing t.
|
|
func StartOfDay(t *gtime.Time) *gtime.Time {
|
|
return gtime.NewFromStr(t.Format(LayoutDate) + " 00:00:00")
|
|
}
|
|
|
|
// EndOfDay returns the end (23:59:59) of the day containing t.
|
|
func EndOfDay(t *gtime.Time) *gtime.Time {
|
|
return gtime.NewFromStr(t.Format(LayoutDate) + " 23:59:59")
|
|
}
|