feat(timex): 自 go-hua/common 迁入时间日期工具并独立成包
- NT/UTC 时间戳互转、时间字符串转毫秒时间戳、指定年月天数 - 附单元测试、examples/timex 例程与包 README
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// timex 包示例:时间日期工具(NT/UTC 时间戳互转、时间字符串转毫秒时间戳、月份天数)
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.zeroonesoft.cn/golib/zogo/timex"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Windows NT 时间戳与 Unix 时间戳互转
|
||||
nt := timex.UtcToNt(1000000000)
|
||||
fmt.Println("Unix 转 NT:", nt)
|
||||
fmt.Println("NT 转 Unix:", timex.NtToUtc(nt))
|
||||
|
||||
// 时间字符串转毫秒时间戳
|
||||
ts, err := timex.TimeStrToTimestamp("2026-08-29 12:00:00")
|
||||
fmt.Println("时间字符串转毫秒时间戳:", ts, "错误:", err)
|
||||
|
||||
// 查询指定年月有多少天
|
||||
fmt.Println("2026年2月天数:", timex.GetYearMonthToDay(2026, 2))
|
||||
fmt.Println("2024年2月天数:", timex.GetYearMonthToDay(2024, 2))
|
||||
}
|
||||
Reference in New Issue
Block a user