timex

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const SimpleDate = "2006-01-02"
View Source
const SimpleTime = "2006-01-02 15:04:05"
View Source
const SimpleTimeMills = "2006-01-02 15:04:05.000"

Variables

This section is empty.

Functions

func CurrentMillis added in v1.0.1

func CurrentMillis() int64

CurrentMillis return unix mills timestamp for now

func Date added in v1.4.0

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

Date create a time, at the beginning of day.

func LocalDate added in v1.4.0

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

LocalDate create a time, at the beginning of day, at local time zone.

func MustParse added in v1.8.4

func MustParse(layout string, value string) time.Time

MustParse parse time string with layout. If parse failed, panic

func MustParseLocal added in v1.8.4

func MustParseLocal(layout string, value string) time.Time

MustParseLocal parse time string with layout, in local Location. If parse failed, panic

func OfEpochMills added in v1.9.0

func OfEpochMills(millis int64) time.Time

OfEpochMills convert unix epoch mills to time

func OfEpochTime added in v1.9.0

func OfEpochTime(secs int64) time.Time

OfEpochTime convert unix epoch seconds to time

func ParseLocal added in v1.2.0

func ParseLocal(layout string, value string) (time.Time, error)

ParseLocal parse time string with layout, in local Location

func ToEpochMills

func ToEpochMills(t time.Time) int64

ToEpochMills convert time to unix epoch millis

func TruncateToDay added in v1.9.0

func TruncateToDay(t time.Time) time.Time

TruncateToDay return the beginning time of the day.

func TruncateToHour added in v1.9.0

func TruncateToHour(t time.Time) time.Time

TruncateToHour return the beginning time of the hour.

func TruncateToMinute added in v1.9.0

func TruncateToMinute(t time.Time) time.Time

TruncateToMinute return the beginning time of the minute.

func TruncateToMonth added in v1.9.0

func TruncateToMonth(t time.Time) time.Time

TruncateToMonth return the beginning time of the month.

func TruncateToWeek added in v1.9.0

func TruncateToWeek(t time.Time) time.Time

TruncateToWeek return the beginning time of the week(Sunday).

func TruncateToYear added in v1.9.0

func TruncateToYear(t time.Time) time.Time

TruncateToYear return the beginning time of the month.

Types

type Stopwatch added in v1.0.1

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

Stopwatch for measure elapsed time. This class is NOT thread-safe.

func NewStopwatch added in v1.0.1

func NewStopwatch() *Stopwatch

NewStopwatch create new Stopwatch, not started.

func NewStopwatchStarted added in v1.0.1

func NewStopwatchStarted() *Stopwatch

NewStopwatchStarted create new Stopwatch, then start it.

func (*Stopwatch) Elapsed added in v1.0.1

func (w *Stopwatch) Elapsed() time.Duration

Elapsed return elapsed time. If not started, always return zero; If started and not stopped, return time interval from begin time to now; If stopped, return elapsed time duration from started time to stopped time.

func (*Stopwatch) ElapsedMillis added in v1.6.0

func (w *Stopwatch) ElapsedMillis() int64

ElapsedMillis return elapsed time by milli-seconds. If not started, always return zero; If started and not stopped, return time interval from begin time to now; If stopped, return elapsed time duration from started time to stopped time.

func (*Stopwatch) Start added in v1.0.1

func (w *Stopwatch) Start() bool

Start the Stopwatch. If StopWatch is already started, return false. A stopped Stopwatch can start again.

func (*Stopwatch) Stop added in v1.0.1

func (w *Stopwatch) Stop() bool

Stop the Stopwatch. The elapsed time will not changed after stopped. Return true if stop succeed. If Stopwatch is not started, or already stopped, return false.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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