time

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 6 Imported by: 0

Documentation

Overview

The time package 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"
	Kitchen = "3:04PM"
	// Special case: use Z to get the time zone formatted according to ISO 8601,
	// which is -0700 or Z for UTC
	ISO8601 = "2006-01-02T15:04:05Z"
)

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.) 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.

View Source
const (
	Sunday = iota
	Monday
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
)

Days of the week.

Variables

This section is empty.

Functions

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

Ticker 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.

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 // 2008 is 2008
	Month, Day           int   // Sep-17 is 9, 17
	Hour, Minute, Second int   // 10:43:12 is 10, 43, 12
	Weekday              int   // Sunday, Monday, ...
	ZoneOffset           int   // seconds east of UTC
	Zone                 string
}

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, ISO8601 and others describe standard representations.

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.

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, ISO8601 and others describe standard representations.

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.

Jump to

Keyboard shortcuts

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