Files
zogo/timex/README.md
T
4566704 ca9dedaf82 feat(timex): 自 go-hua/common 迁入时间日期工具并独立成包
- NT/UTC 时间戳互转、时间字符串转毫秒时间戳、指定年月天数
- 附单元测试、examples/timex 例程与包 README
2026-09-20 12:20:50 +08:00

967 B
Raw Permalink Blame History

timex

时间与日期工具:Windows NT 时间戳与 Unix 时间戳互转、时间字符串转毫秒时间戳、 查询指定年月的天数。

迁移自 go-hua/common(原 time.go / date.go)。

用法

import "git.zeroonesoft.cn/golib/zogo/timex"

// Windows NT 时间戳(100 纳秒,1601 纪元)与 Unix 秒级时间戳互转
nt := timex.UtcToNt(1000000000)
unix := timex.NtToUtc(nt)

// 时间字符串 → 毫秒时间戳(本地时区,格式 2006-01-02 15:04:05)
ts, err := timex.TimeStrToTimestamp("2026-08-29 12:00:00")

// 指定年月有多少天(自动处理闰年)
timex.GetYearMonthToDay(2024, 2) // 29

完整可运行例程:examples/timex/main.go

注意

  • NtToUtc/UtcToNt 为秒级精度整数运算(NT 侧按 1e7 折算),无溢出保护。
  • TimeStrToTimestamp 只接受 2006-01-02 15:04:05 一种格式,其他格式自行用 标准库 time.ParseInLocation。