timex

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: BSD-2-Clause Imports: 2 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 Date

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

Date create a time, at the beginning of day.

func EpochMills

func EpochMills() int64

EpochMills return unix mills timestamp for now

func LocalDate

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

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

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

func MustParseLocal

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

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

func OfEpochMills

func OfEpochMills(millis int64) time.Time

OfEpochMills convert unix epoch mills to time

func OfEpochSeconds

func OfEpochSeconds(secs int64) time.Time

OfEpochSeconds convert unix epoch seconds to time

func ParseLocal

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

func TruncateToDay(t time.Time) time.Time

TruncateToDay return the beginning time of the day.

func TruncateToHour

func TruncateToHour(t time.Time) time.Time

TruncateToHour return the beginning time of the hour.

func TruncateToMinute

func TruncateToMinute(t time.Time) time.Time

TruncateToMinute return the beginning time of the minute.

func TruncateToMonth

func TruncateToMonth(t time.Time) time.Time

TruncateToMonth return the beginning time of the month.

func TruncateToWeek

func TruncateToWeek(t time.Time) time.Time

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

func TruncateToYear

func TruncateToYear(t time.Time) time.Time

TruncateToYear return the beginning time of the month.

Types

type Stopwatch

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

Stopwatch for measure elapsed time. The zero value is valid, as an un-started stopwatch. This is not thread-safe.

func NewStopwatch

func NewStopwatch() *Stopwatch

NewStopwatch create new Stopwatch.

func NewStopwatchStarted

func NewStopwatchStarted() *Stopwatch

NewStopwatchStarted create new Stopwatch, then start it.

func (*Stopwatch) Elapsed

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

Elapsed return elapsed time.

func (*Stopwatch) ElapsedMillis

func (w *Stopwatch) ElapsedMillis() int64

ElapsedMillis return elapsed time by milliseconds.

func (*Stopwatch) ElapsedNanos

func (w *Stopwatch) ElapsedNanos() int64

ElapsedNanos return elapsed time by nanoseconds.

func (*Stopwatch) Reset

func (w *Stopwatch) Reset()

Reset resets the Stopwatch. The elapsed time will set to zero, the status will set to not running.

func (*Stopwatch) Start

func (w *Stopwatch) Start()

Start the Stopwatch. If StopWatch is already started, panics with an error. A stopped Stopwatch can start again.

func (*Stopwatch) Started added in v2.1.0

func (w *Stopwatch) Started() bool

Started returns if this StopWatch is started.

func (*Stopwatch) Stop

func (w *Stopwatch) Stop()

Stop the Stopwatch. The elapsed time will not when stopwatch is stopped. If Stopwatch is not started, panics with an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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