Documentation ¶
Overview ¶
Package time provides functionality for measuring and displaying time.
Index ¶
Constants ¶
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
const ( Sunday = iota Monday Tuesday Wednesday Thursday Friday Saturday )
Days of the week.
Variables ¶
This section is empty.
Functions ¶
func After ¶
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.
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.
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 ¶
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 ¶
SecondsToLocalTime converts sec, in number of seconds since the Unix epoch, into a parsed Time value in the local time zone.
func SecondsToUTC ¶
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 ¶
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.
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 ¶
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.