xtime

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RFC3339Format       = time.RFC3339
	DateFormat          = "2006-01-02"
	DateTimeFormat      = "2006-01-02 15:04:05"
	TimeFormat          = "15:04:05"
	ShortDateTimeFormat = "20060102150405"
	ShortDateFormat     = "20060102"
	ShortTimeFormat     = "150405"

	DaysPerLeapYear       = 366   // 每闰年366天
	DaysPerNormalYear     = 365   // 每常规年365天
	MonthsPerYear         = 12    // 每年12月
	MonthsPerQuarter      = 3     // 每季度3月
	DaysPerNormalMonth    = 30    // 单月30天
	DaysPerDoubleMonth    = 31    // 双月31天
	DaysOfNormalFebruary  = 28    // 二月28天
	DaysOfLeapFebruary    = 29    // 闰年二月29天
	DaysPerWeek           = 7     // 每周7天
	HoursPerDay           = 24    // 每天24小时
	MinutesPerDay         = 1440  // 每天1440分钟
	MinutesPerHour        = 60    // 每小时60分钟
	SecondsPerDay         = 86400 // 每天86400秒
	SecondsPerHour        = 3600  // 每小时3600秒
	SecondsPerMinute      = 60    // 每分钟60秒
	MillisecondsPerSecond = 1000  // 每秒1000毫秒
)

Variables

This section is empty.

Functions

func FormatUnix added in v1.3.3

func FormatUnix(timestamp int64, layout string) string

FormatUnix formats Unix timestamp to layout string

func FormatUnixDate added in v1.0.0

func FormatUnixDate(timestamp int64) string

FormatUnixDate formats Unix timestamp to date string

func FormatUnixDateTime added in v1.0.0

func FormatUnixDateTime(timestamp int64) string

FormatUnixDateTime formats Unix timestamp to time string

func IsLeap added in v1.0.0

func IsLeap(year int) bool

IsLeap check a leap year

func Jitter added in v1.3.5

func Jitter(n int64, factor ...float64) (scale int64)

Jitter simulates jitter by scaling a integer randomly within factor The duration d must be greater than zero; and the scaling factor must be within the range 0 < factor <= 1.0, default factor is 0.1

func JitterTime added in v1.3.5

func JitterTime(d time.Duration, factor ...float64) (scale time.Duration)

JitterTime simulates jitter by scaling a time.Duration randomly within factor The duration d must be greater than zero; and the scaling factor must be within the range 0 < factor <= 1.0, default factor is 0.1

Types

type Time added in v1.0.0

type Time struct {
	time.Time
}

func DaysAfter added in v1.3.3

func DaysAfter(days int) *Time

DaysAfter returns a days-after Time instance of current time

func DaysBefore added in v1.3.3

func DaysBefore(days int) *Time

DaysBefore returns a days-ago Time instance of current time

func Now added in v1.0.0

func Now() *Time

Now return current locale time

func ParseByLayout added in v1.3.3

func ParseByLayout(t string, layout string, loc ...*time.Location) (*Time, error)

ParseByLayout parses a string as a Time instance by layout

func Tomorrow added in v1.3.3

func Tomorrow() *Time

Tomorrow returns a tomorrow Time instance of current time

func Yesterday added in v1.3.3

func Yesterday() *Time

Yesterday returns a yesterday Time instance of current time

func (*Time) BeginOfDay added in v1.0.0

func (t *Time) BeginOfDay() *Time

BeginOfDay return begin time of current day

func (*Time) BeginOfHour added in v1.0.0

func (t *Time) BeginOfHour() *Time

BeginOfHour return begin time of current hour

func (*Time) BeginOfMinute added in v1.0.0

func (t *Time) BeginOfMinute() *Time

BeginOfMinute return begin second of current minute

func (*Time) BeginOfMonth added in v1.0.0

func (t *Time) BeginOfMonth() *Time

BeginOfMonth return begin day time of current month

func (*Time) BeginOfWeek added in v1.0.0

func (t *Time) BeginOfWeek() *Time

BeginOfWeek return begin day time of current week NOTE: week begin from Sunday

func (*Time) BeginOfYear added in v1.0.0

func (t *Time) BeginOfYear() *Time

BeginOfYear return the beginning time of current year

func (*Time) CurrentMilliTime added in v1.0.0

func (t *Time) CurrentMilliTime() int64

GetCurrentMilliTime return current milliseconds

func (*Time) CurrentNanoTime added in v1.0.0

func (t *Time) CurrentNanoTime() int64

GetCurrentNanoTime return current nano seconds

func (*Time) CurrentUnixTime added in v1.0.0

func (t *Time) CurrentUnixTime() int64

GetCurrentUnixTime return current unix seconds

func (*Time) DaysAfter added in v1.3.3

func (t *Time) DaysAfter(days int) *Time

DaysAfter returns a days-after Time instance of assigned t

func (*Time) DaysBefore added in v1.3.3

func (t *Time) DaysBefore(days int) *Time

DaysBefore returns a days-ago Time instance of assigned t

func (*Time) EndOfDay added in v1.0.0

func (t *Time) EndOfDay() *Time

EndOfDay return end time of current day

func (*Time) EndOfHour added in v1.0.0

func (t *Time) EndOfHour() *Time

EndOfHour return end time of current hour

func (*Time) EndOfMinute added in v1.0.0

func (t *Time) EndOfMinute() *Time

EndOfMinute return end second of current minute

func (*Time) EndOfMonth added in v1.0.0

func (t *Time) EndOfMonth() *Time

EndOfMonth return end day time of current month

func (*Time) EndOfWeek added in v1.0.0

func (t *Time) EndOfWeek() *Time

EndOfWeek return end day time of current week NOTE: week end with Saturday

func (*Time) EndOfYear added in v1.0.0

func (t *Time) EndOfYear() *Time

EndOfYear return the end time of current year

func (*Time) Format added in v1.0.0

func (t *Time) Format(layout string) string

Format returns a textual representation of the time value formatted according to layout

func (*Time) Leap added in v1.0.0

func (t *Time) Leap() bool

Leap check current time is leap year or not

func (*Time) Tomorrow added in v1.3.3

func (t *Time) Tomorrow() *Time

Tomorrow return a tomorrow Time instance of assigned t

func (*Time) Yesterday added in v1.3.3

func (t *Time) Yesterday() *Time

Yesterday return a yesterday Time instance of assigned t

Jump to

Keyboard shortcuts

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