time

package
v0.0.0-...-e758773 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2011 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package time provides functionality for measuring and displaying time.

Index

Constants

View Source
const (
	ANSIC    = "Mon Jan _2 15:04:05 2006"
	UnixDate = "Mon Jan _2 15:04:05 MST 2006"
	RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
	RFC822   = "02 Jan 06 1504 MST"
	// RFC822 with Zulu time.
	RFC822Z = "02 Jan 06 1504 -0700"
	RFC850  = "Monday, 02-Jan-06 15:04:05 MST"
	RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST"
	RFC3339 = "2006-01-02T15:04:05Z07:00"
	Kitchen = "3:04PM"
)

These are predefined layouts for use in Time.Format. The standard time used in the layouts is:

Mon Jan 2 15:04:05 MST 2006  (MST is GMT-0700)

which is Unix time 1136243045. (Think of it as 01/02 03:04:05PM '06 -0700.) To define your own format, write down what the standard time would look like formatted your way.

Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats.

Numeric time zone offsets format as follows:

-0700  ±hhmm
-07:00 ±hh:mm

Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus:

Z0700  Z or ±hhmm
Z07:00 Z or ±hh:mm
View Source
const (
	Sunday = iota
	Monday
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
)

Days of the week.

Variables

This section is empty.

Functions

func After

func After(ns int64) <-chan int64

After waits at least ns nanoseconds before sending the current time on the returned channel. It is equivalent to NewTimer(ns).C.

func Nanoseconds

func Nanoseconds() int64

Nanoseconds reports the number of nanoseconds since the Unix epoch, January 1, 1970 00:00:00 UTC.

func Seconds

func Seconds() int64

Seconds reports the number of seconds since the Unix epoch, January 1, 1970 00:00:00 UTC.

func Sleep

func Sleep(ns int64) os.Error

Sleep pauses the current goroutine for at least ns nanoseconds. Higher resolution sleeping may be provided by syscall.Nanosleep on some operating systems.

func Tick

func Tick(ns int64) <-chan int64

Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. Useful for clients that have no need to shut down the ticker.

Types

type ParseError

type ParseError struct {
	Layout     string
	Value      string
	LayoutElem string
	ValueElem  string
	Message    string
}

ParseError describes a problem parsing a time string.

func (*ParseError) String

func (e *ParseError) String() string

String is the string representation of a ParseError.

type Ticker

type Ticker struct {
	C <-chan int64 // The channel on which the ticks are delivered.
	// contains filtered or unexported fields
}

A Ticker holds a synchronous channel that delivers `ticks' of a clock at intervals.

func NewTicker

func NewTicker(ns int64) *Ticker

NewTicker returns a new Ticker containing a channel that will send the time, in nanoseconds, every ns nanoseconds. It adjusts the intervals to make up for pauses in delivery of the ticks. The value of ns must be greater than zero; if not, NewTicker will panic.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop turns off a ticker. After Stop, no more ticks will be sent.

type Time

type Time struct {
	Year                 int64  // 2006 is 2006
	Month, Day           int    // Jan-2 is 1, 2
	Hour, Minute, Second int    // 15:04:05 is 15, 4, 5.
	Weekday              int    // Sunday, Monday, ...
	ZoneOffset           int    // seconds east of UTC, e.g. -7*60*60 for -0700
	Zone                 string // e.g., "MST"
}

Time is the struct representing a parsed time value.

func LocalTime

func LocalTime() *Time

LocalTime returns the current time as a parsed Time value in the local time zone.

func Parse

func Parse(alayout, avalue string) (*Time, os.Error)

Parse parses a formatted string and returns the time value it represents. The layout defines the format by showing the representation of a standard time, which is then used to describe the string to be parsed. Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard representations.For more information about the formats, see the documentation for ANSIC.

Only those elements present in the value will be set in the returned time structure. Also, if the input string represents an inconsistent time (such as having the wrong day of the week), the returned value will also be inconsistent. In any case, the elements of the returned time will be sane: hours in 0..23, minutes in 0..59, day of month in 0..31, etc. Years must be in the range 0000..9999.

func SecondsToLocalTime

func SecondsToLocalTime(sec int64) *Time

SecondsToLocalTime converts sec, in number of seconds since the Unix epoch, into a parsed Time value in the local time zone.

func SecondsToUTC

func SecondsToUTC(sec int64) *Time

SecondsToUTC converts sec, in number of seconds since the Unix epoch, into a parsed Time value in the UTC time zone.

func UTC

func UTC() *Time

UTC returns the current time as a parsed Time value in the UTC time zone.

func (*Time) Format

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

Format returns a textual representation of the time value formatted according to layout. The layout defines the format by showing the representation of a standard time, which is then used to describe the time to be formatted. Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard representations. For more information about the formats, see the documentation for ANSIC.

func (*Time) Seconds

func (t *Time) Seconds() int64

Seconds returns the number of seconds since January 1, 1970 represented by the parsed Time value.

func (*Time) String

func (t *Time) String() string

String returns a Unix-style representation of the time value.

type Timer

type Timer struct {
	C <-chan int64
	// contains filtered or unexported fields
}

The Timer type represents a single event. When the Timer expires, the current time will be sent on C unless the Timer represents an AfterFunc event.

func AfterFunc

func AfterFunc(ns int64, f func()) *Timer

AfterFunc waits at least ns nanoseconds before calling f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.

func NewTimer

func NewTimer(ns int64) *Timer

NewTimer creates a new Timer that will send the current time on its channel after at least ns nanoseconds.

func (*Timer) Stop

func (e *Timer) Stop() (ok bool)

Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the timer has already expired or stopped.

Jump to

Keyboard shortcuts

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