time

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: BSD-3-Clause Imports: 5 Imported by: 1

Documentation

Overview

Package time provide a library for working with time.

Index

Examples

Constants

View Source
const (
	// Day the duration for a day.
	Day = 24 * time.Hour
	// Week the duration for a week.
	Week = 7 * Day
)

Variables

View Source
var (
	ShortDayNames = []string{
		"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
	}

	//
	// ShortMonths provide mapping between text of month, in English,
	// short format to their time.Month value
	//
	ShortMonths = map[string]time.Month{
		"Jan": time.January,
		"Feb": time.February,
		"Mar": time.March,
		"Apr": time.April,
		"May": time.May,
		"Jun": time.June,
		"Jul": time.July,
		"Aug": time.August,
		"Sep": time.September,
		"Oct": time.October,
		"Nov": time.November,
		"Dec": time.December,
	}
)
View Source
var (
	// ErrDurationMissingValue an error when value is missing when parsing
	// duration.
	ErrDurationMissingValue = errors.New("missing value in duration")
)

Functions

func Microsecond

func Microsecond(t *time.Time) int64

Microsecond return the microsecond value of time. For example, if the unix nano seconds is 1612331218913557000 then the micro second value is 913557.

To get the unix microsecond use UnixMicro().

Example
nano := time.Unix(1612331000, 123456789)
fmt.Printf("%d", Microsecond(&nano))
Output:

123456

func ParseDuration

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

ParseDuration extend the capability of standard time.Duration with additional unit suffix: day and week. Day unit end with "d" and week unit end with "w". A day is equal with "24h", an a week is equal to "7d". Unlike standard time.Duration the week or day units must be before hours.

func UnixMicro added in v0.23.0

func UnixMicro(t *time.Time) int64

UnixMicro returns t as a Unix time in microsecond. For example, if the unix nano seconds is 1612331218913557000 then the UnixMicro value is 1612331218913557.

Example
nano := time.Unix(1612331000, 123456789)
fmt.Printf("%d", UnixMicro(&nano))
Output:

1612331000123456

func UnixMilli added in v0.13.0

func UnixMilli(t time.Time) int64

UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC.

Example
nano := time.Unix(1612331000, 123456789)
fmt.Printf("%d", UnixMilli(nano))
Output:

1612331000123

func UnixMilliString added in v0.13.0

func UnixMilliString(t time.Time) string

UnixMilliString returns the UnixMilli() as string.

Example
nano := time.Unix(1612331000, 123456789)
fmt.Printf("%s", UnixMilliString(nano))
Output:

1612331000123

Types

This section is empty.

Jump to

Keyboard shortcuts

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