datetime

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClockPrecision = time.Millisecond * 100
	ISO8601Format  = "2006-01-02T15:04:05-0700"
)
View Source
const (
	Day  = 24 * time.Hour
	Week = 7 * Day
)
View Source
const (
	DateLayout      = "2006-01-02T15:04:05"
	MsTimeLayout    = "2006-01-02T15:04:05.000"
	MicroTimeLayout = "2006-01-02T15:04:05.000000"

	MsPerSecond = 1000
	MsPerMinute = 60 * MsPerSecond
	MsPerHour   = 60 * MsPerMinute
	MsPerDay    = 24 * MsPerHour
	MsPerWeek   = 7 * MsPerDay

	SecondsPerMin  = 60
	SecondsPerHour = 60 * SecondsPerMin
	SecondsPerDay  = 24 * SecondsPerHour
)

Variables

View Source
var (
	FirstDayIsMonday = false
	DefaultLoc       = time.UTC
)

Functions

func DaysCountOfMonth

func DaysCountOfMonth(year, month int) int

DaysCountOfMonth 一个月的天数

func ElapsedDaysBetween

func ElapsedDaysBetween(start, end time.Time) int

ElapsedDaysBetween 获取两个时间中经过的天数

func EndOfWeek

func EndOfWeek(t time.Time) time.Time

EndOfWeek 本周的最后一天

func FirstDayOfYear

func FirstDayOfYear(year int) time.Time

FirstDayOfYear 年度第一天

func FormatMsTime

func FormatMsTime(ms int64) string

func FormatMsTimeUTC added in v1.0.4

func FormatMsTimeUTC(ms int64) string

func FormatNanoTime added in v1.0.4

func FormatNanoTime(nano int64) string

func FormatNanoTimeUTC added in v1.0.4

func FormatNanoTimeUTC(nano int64) string

func FormatTime

func FormatTime(t time.Time) string

func FormatTimeUTC added in v1.0.4

func FormatTimeUTC(t time.Time) string

func GetNextMonday added in v1.0.3

func GetNextMonday(now time.Time) time.Time

GetNextMonday 计算当前时间的下周一的凌晨0点

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear 是否闰年

func LastDayOfYear

func LastDayOfYear(year int) time.Time

LastDayOfYear 年度最后一天

func MidnightTimeOf

func MidnightTimeOf(t time.Time) time.Time

MidnightTimeOf 当日零点

func NextMidnight

func NextMidnight(ts int64) int64

NextMidnight 下一个凌晨

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string, this extends `time.ParseDuration` with days A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".

func PrettyDuration

func PrettyDuration(d time.Duration) string

PrettyDuration returns a string representing the duration in the form of "4d2h3m5s".

func PrettyTime

func PrettyTime(ms int64) string

PrettyTime 返回毫秒时间的字符串显示,100000 => 1d3h46m40s

func StartingOfWeek

func StartingOfWeek(t time.Time) time.Time

StartingOfWeek 本周的起点

func ThisMomentAfterDays

func ThisMomentAfterDays(this time.Time, days int) time.Time

ThisMomentAfterDays N天后的这个时候

func TimeOfMS added in v1.0.10

func TimeOfMS(ms int64) time.Time

func UTCTimeOfMS added in v1.0.10

func UTCTimeOfMS(ms int64) time.Time

Types

type Clock

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

Clock 提供一些对壁钟时间的操作,不适用于高精度的计时场景 设计初衷是为精度至少为秒的上层业务服务, 支持时钟的往前/后调拨

func NewClock

func NewClock(interval time.Duration) *Clock

func (*Clock) DateTime

func (c *Clock) DateTime() string

func (*Clock) Go

func (c *Clock) Go()

func (*Clock) Now

func (c *Clock) Now() time.Time

func (*Clock) NowMs

func (c *Clock) NowMs() int64

func (*Clock) Reset

func (c *Clock) Reset()

Reset 恢复时钟

func (*Clock) Stop

func (c *Clock) Stop()

func (*Clock) Travel

func (c *Clock) Travel(d time.Duration)

Travel 拨动时钟(时间旅行)

Jump to

Keyboard shortcuts

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