Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration 将时间间隔格式化为可读的字符串。
参数:
- d: 时间间隔
返回值:
- string: 格式化后的字符串,自动选择合适的单位
用法:
duration := 100 * time.Millisecond formatted := FormatDuration(duration) // formatted = "100.00ms"
特点:
- 自动选择合适的单位
- 精度 2 位小数
- 支持纳秒到小时
局限:
- 小于 1 纳秒时返回 "0ns"
- 精度固定为 2 位小数
func ToTimestamp ¶
ToTimestamp 将时间转换为 Unix 时间戳。
参数:
- tm: 时间对象
返回值:
- int64: Unix 时间戳(秒数)
用法:
now := time.Now() timestamp := ToTimestamp(now) // timestamp = 1700000000
特点:
- 返回秒级精度
- 与 time.Unix() 互逆
局限:
- 只返回秒级精度,丢失毫秒信息
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.