cytime

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) (r string)

FormatDuration 将时间间隔格式化为可读的字符串。

参数:

  • d: 时间间隔

返回值:

  • string: 格式化后的字符串,自动选择合适的单位

用法:

duration := 100 * time.Millisecond
formatted := FormatDuration(duration)
// formatted = "100.00ms"

特点:

  • 自动选择合适的单位
  • 精度 2 位小数
  • 支持纳秒到小时

局限:

  • 小于 1 纳秒时返回 "0ns"
  • 精度固定为 2 位小数

func ParseToDayEnd

func ParseToDayEnd(s string) (time.Time, error)

func ParseToDayStart

func ParseToDayStart(s string) (time.Time, error)

func ToTimestamp

func ToTimestamp(tm time.Time) int64

ToTimestamp 将时间转换为 Unix 时间戳。

参数:

  • tm: 时间对象

返回值:

  • int64: Unix 时间戳(秒数)

用法:

now := time.Now()
timestamp := ToTimestamp(now)
// timestamp = 1700000000

特点:

  • 返回秒级精度
  • 与 time.Unix() 互逆

局限:

  • 只返回秒级精度,丢失毫秒信息

Types

This section is empty.

Jump to

Keyboard shortcuts

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