times

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntervalYear = iota
	IntervalDay
	IntervalHour
	IntervalMinute
	IntervalSecond
	IntervalNow
)
View Source
const (
	Nanosecond  = time.Nanosecond
	Microsecond = time.Microsecond
	Millisecond = time.Millisecond
	Second      = time.Second
	Minute      = time.Minute
	Hour        = time.Hour
	Day         = time.Hour * 24
	Week        = Day * 7
)

Variables

View Source
var (
	Zero time.Time // 零值时间
)

Functions

func CalcNextSec

func CalcNextSec(sec int) int

CalcNextSec 计算下一个N秒在多少秒之后

func CalcNextSecWithTime

func CalcNextSecWithTime(t time.Time, sec int) int

CalcNextSecWithTime 计算下一个N秒在多少秒之后

func CalcNextTimeWithRefer added in v0.0.18

func CalcNextTimeWithRefer(now time.Time, refer time.Duration) time.Time

CalcNextTimeWithRefer 根据参考时间计算下一个整点时间

  • 假设当 now 为 14:15:16 , 参考时间为 10 分钟, 则返回 14:20:00
  • 假设当 now 为 14:15:16 , 参考时间为 20 分钟, 则返回 14:20:00

当 refer 小于 1 分钟时,将会返回当前时间

func Date added in v0.0.2

func Date(year int, month time.Month, day int) time.Time

Date 返回一个特定日期的时间

func DateWithHMS added in v0.0.2

func DateWithHMS(year int, month time.Month, day, hour, min, sec int) time.Time

DateWithHMS 返回一个精确到秒的时间

func GetDayLast added in v0.0.28

func GetDayLast(t time.Time) time.Time

GetDayLast 获取某天的最后一刻

  • 最后一刻即 23:59:59

func GetDayZero added in v0.0.3

func GetDayZero(t time.Time, day int) time.Time

GetDayZero 获取 t 增加 day 天后的零点时间

func GetDeltaDay added in v0.0.2

func GetDeltaDay(t1, t2 time.Time) int

GetDeltaDay 获取两个时间需要加减的天数

func GetDeltaWeek added in v0.0.2

func GetDeltaWeek(t1, t2 time.Time) int

GetDeltaWeek 获取两个时间需要加减的周数

func GetHSMFromString added in v0.0.2

func GetHSMFromString(timeStr, layout string) (hour, min, sec int)

GetHSMFromString 从时间字符串中获取时分秒

func GetMondayZero

func GetMondayZero(t time.Time) time.Time

GetMondayZero 获取本周一零点

func GetMonthDays

func GetMonthDays(t time.Time) int

GetMonthDays 获取一个时间当月共有多少天

func GetNextDayInterval

func GetNextDayInterval(t time.Time) time.Duration

GetNextDayInterval 获取一个时间到下一天间隔多少秒

func GetSecond

func GetSecond(d time.Duration) int

GetSecond 获取共有多少秒

func GetTimeFromString added in v0.0.2

func GetTimeFromString(timeStr, layout string) time.Time

GetTimeFromString 将时间字符串转化为时间

func GetToday

func GetToday(t time.Time) time.Time

GetToday 获取一个时间的今天

func GetYesterday added in v0.0.28

func GetYesterday(t time.Time) time.Time

GetYesterday 获取昨天

func GetYesterdayLast added in v0.0.28

func GetYesterdayLast(t time.Time) time.Time

GetYesterdayLast 获取昨天最后一刻

func IntervalFormat

func IntervalFormat(time1, time2 time.Time) string

IntervalFormat 返回指定时间戳之间的间隔

  • 使用传入的时间进行计算换算,将结果体现为几年前、几天前、几小时前、几分钟前、几秒前。

func IntervalFormatSet

func IntervalFormatSet(intervalType int, str string)

IntervalFormatSet 针对 IntervalFormat 函数设置格式化内容

func IsSameDay

func IsSameDay(t1, t2 time.Time) bool

IsSameDay 两个时间是否是同一天

func IsSameHour

func IsSameHour(t1, t2 time.Time) bool

IsSameHour 两个时间是否是同一小时

func WeekDay

func WeekDay(t time.Time) int

WeekDay 获取一个时间是星期几

  • 1 ~ 7

Types

type Period added in v0.0.3

type Period [2]time.Time

Period 表示一个时间段

func NewPeriod added in v0.0.3

func NewPeriod(start, end time.Time) Period

NewPeriod 创建一个时间段

  • 如果 start 比 end 晚,则会自动交换两个时间

func NewPeriodWithDay added in v0.0.3

func NewPeriodWithDay(t time.Time, day int) Period

NewPeriodWithDay 创建一个时间段,从 t 开始,持续 day 天

func NewPeriodWithDayZero added in v0.0.3

func NewPeriodWithDayZero(t time.Time, day int) Period

NewPeriodWithDayZero 创建一个时间段,从 t 开始,持续到 day 天后的 0 点

func NewPeriodWithHour added in v0.0.3

func NewPeriodWithHour(t time.Time, hour int) Period

NewPeriodWithHour 创建一个时间段,从 t 开始,持续 hour 小时

func NewPeriodWithMicrosecond added in v0.0.3

func NewPeriodWithMicrosecond(t time.Time, microsecond int) Period

NewPeriodWithMicrosecond 创建一个时间段,从 t 开始,持续 microsecond 微秒

func NewPeriodWithMillisecond added in v0.0.3

func NewPeriodWithMillisecond(t time.Time, millisecond int) Period

NewPeriodWithMillisecond 创建一个时间段,从 t 开始,持续 millisecond 毫秒

func NewPeriodWithMinute added in v0.0.3

func NewPeriodWithMinute(t time.Time, minute int) Period

NewPeriodWithMinute 创建一个时间段,从 t 开始,持续 minute 分钟

func NewPeriodWithNanosecond added in v0.0.3

func NewPeriodWithNanosecond(t time.Time, nanosecond int) Period

NewPeriodWithNanosecond 创建一个时间段,从 t 开始,持续 nanosecond 纳秒

func NewPeriodWithSecond added in v0.0.3

func NewPeriodWithSecond(t time.Time, second int) Period

NewPeriodWithSecond 创建一个时间段,从 t 开始,持续 second 秒

func NewPeriodWithTimeArray added in v0.0.3

func NewPeriodWithTimeArray(times [2]time.Time) Period

NewPeriodWithTimeArray 创建一个时间段

func (Period) Day added in v0.0.3

func (slf Period) Day() int

Day 返回时间段的持续天数

func (Period) Duration added in v0.0.3

func (slf Period) Duration() time.Duration

Duration 返回时间段的持续时间

func (Period) End added in v0.0.3

func (slf Period) End() time.Time

End 返回时间段的结束时间

func (Period) Hour added in v0.0.3

func (slf Period) Hour() int

Hour 返回时间段的持续小时数

func (Period) IsAfter added in v0.0.3

func (slf Period) IsAfter(t time.Time) bool

IsAfter 判断时间段是否在指定时间之后

func (Period) IsBefore added in v0.0.3

func (slf Period) IsBefore(t time.Time) bool

IsBefore 判断时间段是否在指定时间之前

func (Period) IsBetween added in v0.0.3

func (slf Period) IsBetween(t time.Time) bool

IsBetween 判断指定时间是否在时间段之间

func (Period) IsBetweenOrEqual added in v0.0.3

func (slf Period) IsBetweenOrEqual(t time.Time) bool

IsBetweenOrEqual 判断指定时间是否在时间段之间或者等于时间段的开始或结束时间

func (Period) IsBetweenOrEqualPeriod added in v0.0.3

func (slf Period) IsBetweenOrEqualPeriod(t Period) bool

IsBetweenOrEqualPeriod 判断指定时间是否在时间段之间或者等于时间段的开始或结束时间

func (Period) IsInvalid added in v0.0.3

func (slf Period) IsInvalid() bool

IsInvalid 判断时间段是否无效

func (Period) IsOngoing added in v0.0.3

func (slf Period) IsOngoing(t time.Time) bool

IsOngoing 判断指定时间是否正在进行时

  • 如果时间段的开始时间在指定时间之前或者等于指定时间,且时间段的结束时间在指定时间之后,则返回 true

func (Period) IsOverlap added in v0.0.3

func (slf Period) IsOverlap(t Period) bool

IsOverlap 判断时间段是否与指定时间段重叠

func (Period) IsZero added in v0.0.3

func (slf Period) IsZero() bool

IsZero 判断时间段是否为零值

func (Period) Microseconds added in v0.0.3

func (slf Period) Microseconds() int

Microseconds 返回时间段的持续微秒数

func (Period) Milliseconds added in v0.0.3

func (slf Period) Milliseconds() int

Milliseconds 返回时间段的持续毫秒数

func (Period) Minute added in v0.0.3

func (slf Period) Minute() int

Minute 返回时间段的持续分钟数

func (Period) Nanoseconds added in v0.0.3

func (slf Period) Nanoseconds() int

Nanoseconds 返回时间段的持续纳秒数

func (Period) Seconds added in v0.0.3

func (slf Period) Seconds() int

Seconds 返回时间段的持续秒数

func (Period) Start added in v0.0.3

func (slf Period) Start() time.Time

Start 返回时间段的开始时间

Jump to

Keyboard shortcuts

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