timeutil

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Layout2DateDay    = "2006-01-02"
	Layout2DateHour   = "2006-01-02 15"
	Layout2DateMinute = "2006-01-02 15:04"
	Layout2DateTime   = "2006-01-02 15:04:05"
	Layout2StampMilli = "2006-01-02 15:04:05.000"
	Layout2StampMicro = "2006-01-02 15:04:05.000000"
	Layout2StampNano  = "2006-01-02 15:04:05.000000000"
)

time layout format 这里只定义 layout 格式,请按需选择即可,格式化输出请使用: t.Format(layout)

Variables

This section is empty.

Functions

func DayRange

func DayRange(t time.Time, loc *time.Location) (time.Time, time.Time)

DayRange 根据传入时间,获取当天的起始时间点

func MonthRange

func MonthRange(t time.Time, loc *time.Location) (time.Time, time.Time)

MonthRange 根据传入时间,获取当月的起始时间点

func PositiveUnix

func PositiveUnix(t time.Time) int64

PositiveUnix 获取 time.Time 的时间戳, 若time小于1970-01-01 00:00:00 则返回0

func Range

func Range(start, end time.Time, step time.Duration) []time.Time

Range 根据 [start,end]指定的范围,按 step 间隔生成时间切片

func RangeN

func RangeN(start time.Time, step time.Duration, n int) []time.Time

RangeN 从指定时间开始,按 step 时间步长,生成 n 个 time.Time时间切片 返回 [start, start+n*step] 范围内的时间切片

func Unix

func Unix(t time.Time) int64

Unix 时间戳(精确到秒)

func UnixMicro

func UnixMicro(t time.Time) int64

UnixMicro 时间戳(精确到微秒)

func UnixMilli

func UnixMilli(t time.Time) int64

UnixMilli 时间戳(精确到毫秒)

func UnixNano

func UnixNano(t time.Time) int64

UnixNano 时间戳(精确到纳秒)

Types

type Stopwatch

type Stopwatch struct {
	// contains filtered or unexported fields
}

Stopwatch 用于计算一段代码所运行的时间

func NewStopwatch

func NewStopwatch() *Stopwatch

NewStopwatch 根据系统当前时间初始化 start 时间

func (*Stopwatch) ElapsedTime

func (sw *Stopwatch) ElapsedTime() time.Duration

ElapsedTime 返回自 Stopwatch 创建以来所经过的时间

Jump to

Keyboard shortcuts

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