Involved Source Filesformat.gosleep.gosys_unix.gotick.go
Package time provides functionality for measuring and displaying time.
The calendrical calculations always assume a Gregorian calendar, with
no leap seconds.
Monotonic Clocks
Operating systems provide both a “wall clock,” which is subject to
changes for clock synchronization, and a “monotonic clock,” which is
not. The general rule is that the wall clock is for telling time and
the monotonic clock is for measuring time. Rather than split the API,
in this package the Time returned by time.Now contains both a wall
clock reading and a monotonic clock reading; later time-telling
operations use the wall clock reading, but later time-measuring
operations, specifically comparisons and subtractions, use the
monotonic clock reading.
For example, this code always computes a positive elapsed time of
approximately 20 milliseconds, even if the wall clock is changed during
the operation being timed:
start := time.Now()
... operation that takes 20 milliseconds ...
t := time.Now()
elapsed := t.Sub(start)
Other idioms, such as time.Since(start), time.Until(deadline), and
time.Now().Before(deadline), are similarly robust against wall clock
resets.
The rest of this section gives the precise details of how operations
use monotonic clocks, but understanding those details is not required
to use this package.
The Time returned by time.Now contains a monotonic clock reading.
If Time t has a monotonic clock reading, t.Add adds the same duration to
both the wall clock and monotonic clock readings to compute the result.
Because t.AddDate(y, m, d), t.Round(d), and t.Truncate(d) are wall time
computations, they always strip any monotonic clock reading from their results.
Because t.In, t.Local, and t.UTC are used for their effect on the interpretation
of the wall time, they also strip any monotonic clock reading from their results.
The canonical way to strip a monotonic clock reading is to use t = t.Round(0).
If Times t and u both contain monotonic clock readings, the operations
t.After(u), t.Before(u), t.Equal(u), and t.Sub(u) are carried out
using the monotonic clock readings alone, ignoring the wall clock
readings. If either t or u contains no monotonic clock reading, these
operations fall back to using the wall clock readings.
On some systems the monotonic clock will stop if the computer goes to sleep.
On such a system, t.Sub(u) may not accurately reflect the actual
time that passed between t and u.
Because the monotonic clock reading has no meaning outside
the current process, the serialized forms generated by t.GobEncode,
t.MarshalBinary, t.MarshalJSON, and t.MarshalText omit the monotonic
clock reading, and t.Format provides no format for it. Similarly, the
constructors time.Date, time.Parse, time.ParseInLocation, and time.Unix,
as well as the unmarshalers t.GobDecode, t.UnmarshalBinary.
t.UnmarshalJSON, and t.UnmarshalText always create times with
no monotonic clock reading.
Note that the Go == operator compares not just the time instant but
also the Location and the monotonic clock reading. See the
documentation for the Time type for a discussion of equality
testing for Time values.
For debugging, the result of t.String does include the monotonic
clock reading if present. If t != u because of different monotonic clock readings,
that difference will be visible when printing t.String() and u.String().
zoneinfo.gozoneinfo_read.gozoneinfo_unix.go
Code Examples
package main
import (
"fmt"
"time"
)
var c chan int
func handle(int) {}
func main() {
select {
case m := <-c:
handle(m)
case <-time.After(10 * time.Second):
fmt.Println("timed out")
}
}
package main
import (
"fmt"
"time"
)
func main() {
t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
fmt.Printf("Go launched at %s\n", t.Local())
}
package main
import (
"fmt"
"time"
)
func expensiveCall() {}
func main() {
t0 := time.Now()
expensiveCall()
t1 := time.Now()
fmt.Printf("The call took %v to run.\n", t1.Sub(t0))
}
package main
import (
"fmt"
"time"
)
func main() {
h, _ := time.ParseDuration("4h30m")
fmt.Printf("I've got %.1f hours of work left.", h.Hours())
}
package main
import (
"fmt"
"time"
)
func main() {
u, _ := time.ParseDuration("1s")
fmt.Printf("One second is %d microseconds.\n", u.Microseconds())
}
package main
import (
"fmt"
"time"
)
func main() {
u, _ := time.ParseDuration("1s")
fmt.Printf("One second is %d milliseconds.\n", u.Milliseconds())
}
package main
import (
"fmt"
"time"
)
func main() {
m, _ := time.ParseDuration("1h30m")
fmt.Printf("The movie is %.0f minutes long.", m.Minutes())
}
package main
import (
"fmt"
"time"
)
func main() {
u, _ := time.ParseDuration("1µs")
fmt.Printf("One microsecond is %d nanoseconds.\n", u.Nanoseconds())
}
package main
import (
"fmt"
"time"
)
func main() {
d, err := time.ParseDuration("1h15m30.918273645s")
if err != nil {
panic(err)
}
round := []time.Duration{
time.Nanosecond,
time.Microsecond,
time.Millisecond,
time.Second,
2 * time.Second,
time.Minute,
10 * time.Minute,
time.Hour,
}
for _, r := range round {
fmt.Printf("d.Round(%6s) = %s\n", r, d.Round(r).String())
}
}
package main
import (
"fmt"
"time"
)
func main() {
m, _ := time.ParseDuration("1m30s")
fmt.Printf("Take off in t-%.0f seconds.", m.Seconds())
}
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(1*time.Hour + 2*time.Minute + 300*time.Millisecond)
fmt.Println(300 * time.Millisecond)
}
package main
import (
"fmt"
"time"
)
func main() {
d, err := time.ParseDuration("1h15m30.918273645s")
if err != nil {
panic(err)
}
trunc := []time.Duration{
time.Nanosecond,
time.Microsecond,
time.Millisecond,
time.Second,
2 * time.Second,
time.Minute,
10 * time.Minute,
time.Hour,
}
for _, t := range trunc {
fmt.Printf("d.Truncate(%6s) = %s\n", t, d.Truncate(t).String())
}
}
package main
import (
"fmt"
"time"
)
func main() {
loc := time.FixedZone("UTC-8", -8*60*60)
t := time.Date(2009, time.November, 10, 23, 0, 0, 0, loc)
fmt.Println("The time is:", t.Format(time.RFC822))
}
package main
import (
"fmt"
"time"
)
func main() {
location, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
panic(err)
}
timeInUTC := time.Date(2018, 8, 30, 12, 0, 0, 0, time.UTC)
fmt.Println(timeInUTC.In(location))
}
package main
import (
"fmt"
"time"
)
func main() {
// China doesn't have daylight saving. It uses a fixed 8 hour offset from UTC.
secondsEastOfUTC := int((8 * time.Hour).Seconds())
beijing := time.FixedZone("Beijing Time", secondsEastOfUTC)
// If the system has a timezone database present, it's possible to load a location
// from that, e.g.:
// newYork, err := time.LoadLocation("America/New_York")
// Creating a time requires a location. Common locations are time.Local and time.UTC.
timeInUTC := time.Date(2009, 1, 1, 12, 0, 0, 0, time.UTC)
sameTimeInBeijing := time.Date(2009, 1, 1, 20, 0, 0, 0, beijing)
// Although the UTC clock time is 1200 and the Beijing clock time is 2000, Beijing is
// 8 hours ahead so the two dates actually represent the same instant.
timesAreEqual := timeInUTC.Equal(sameTimeInBeijing)
fmt.Println(timesAreEqual)
}
package main
import (
"fmt"
"time"
)
func main() {
_, month, day := time.Now().Date()
if month == time.November && day == 10 {
fmt.Println("Happy Go day!")
}
}
package main
import (
"fmt"
"time"
)
func main() {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
done := make(chan bool)
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-ticker.C:
fmt.Println("Current time: ", t)
}
}
}
package main
import (
"fmt"
"time"
)
func main() {
// See the example for Time.Format for a thorough description of how
// to define the layout string to parse a time.Time value; Parse and
// Format use the same model to describe their input and output.
// longForm shows by example how the reference time would be represented in
// the desired layout.
const longForm = "Jan 2, 2006 at 3:04pm (MST)"
t, _ := time.Parse(longForm, "Feb 3, 2013 at 7:54pm (PST)")
fmt.Println(t)
// shortForm is another way the reference time would be represented
// in the desired layout; it has no time zone present.
// Note: without explicit zone, returns time in UTC.
const shortForm = "2006-Jan-02"
t, _ = time.Parse(shortForm, "2013-Feb-03")
fmt.Println(t)
// Some valid layouts are invalid time values, due to format specifiers
// such as _ for space padding and Z for zone information.
// For example the RFC3339 layout 2006-01-02T15:04:05Z07:00
// contains both Z and a time zone offset in order to handle both valid options:
// 2006-01-02T15:04:05Z
// 2006-01-02T15:04:05+07:00
t, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
fmt.Println(t)
t, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05+07:00")
fmt.Println(t)
_, err := time.Parse(time.RFC3339, time.RFC3339)
fmt.Println("error", err) // Returns an error as the layout is not a valid time value
}
package main
import (
"fmt"
"time"
)
func main() {
hours, _ := time.ParseDuration("10h")
complex, _ := time.ParseDuration("1h10m10s")
micro, _ := time.ParseDuration("1µs")
// The package also accepts the incorrect but common prefix u for micro.
micro2, _ := time.ParseDuration("1us")
fmt.Println(hours)
fmt.Println(complex)
fmt.Printf("There are %.0f seconds in %v.\n", complex.Seconds(), complex)
fmt.Printf("There are %d nanoseconds in %v.\n", micro.Nanoseconds(), micro)
fmt.Printf("There are %6.2e seconds in %v.\n", micro2.Seconds(), micro)
}
package main
import (
"fmt"
"time"
)
func main() {
loc, _ := time.LoadLocation("Europe/Berlin")
// This will look for the name CEST in the Europe/Berlin time zone.
const longForm = "Jan 2, 2006 at 3:04pm (MST)"
t, _ := time.ParseInLocation(longForm, "Jul 9, 2012 at 5:02am (CEST)", loc)
fmt.Println(t)
// Note: without explicit zone, returns time in given location.
const shortForm = "2006-Jan-02"
t, _ = time.ParseInLocation(shortForm, "2012-Jul-09", loc)
fmt.Println(t)
}
package main
import (
"time"
)
func main() {
time.Sleep(100 * time.Millisecond)
}
package main
import (
"fmt"
"time"
)
func statusUpdate() string { return "" }
func main() {
c := time.Tick(5 * time.Second)
for next := range c {
fmt.Printf("%v %s\n", next, statusUpdate())
}
}
package main
import (
"fmt"
"time"
)
func main() {
start := time.Date(2009, 1, 1, 12, 0, 0, 0, time.UTC)
afterTenSeconds := start.Add(time.Second * 10)
afterTenMinutes := start.Add(time.Minute * 10)
afterTenHours := start.Add(time.Hour * 10)
afterTenDays := start.Add(time.Hour * 24 * 10)
fmt.Printf("start = %v\n", start)
fmt.Printf("start.Add(time.Second * 10) = %v\n", afterTenSeconds)
fmt.Printf("start.Add(time.Minute * 10) = %v\n", afterTenMinutes)
fmt.Printf("start.Add(time.Hour * 10) = %v\n", afterTenHours)
fmt.Printf("start.Add(time.Hour * 24 * 10) = %v\n", afterTenDays)
}
package main
import (
"fmt"
"time"
)
func main() {
start := time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC)
oneDayLater := start.AddDate(0, 0, 1)
oneMonthLater := start.AddDate(0, 1, 0)
oneYearLater := start.AddDate(1, 0, 0)
fmt.Printf("oneDayLater: start.AddDate(0, 0, 1) = %v\n", oneDayLater)
fmt.Printf("oneMonthLater: start.AddDate(0, 1, 0) = %v\n", oneMonthLater)
fmt.Printf("oneYearLater: start.AddDate(1, 0, 0) = %v\n", oneYearLater)
}
package main
import (
"fmt"
"time"
)
func main() {
year2000 := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
year3000 := time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)
isYear3000AfterYear2000 := year3000.After(year2000) // True
isYear2000AfterYear3000 := year2000.After(year3000) // False
fmt.Printf("year3000.After(year2000) = %v\n", isYear3000AfterYear2000)
fmt.Printf("year2000.After(year3000) = %v\n", isYear2000AfterYear3000)
}
package main
import (
"fmt"
"time"
)
func main() {
t := time.Date(2017, time.November, 4, 11, 0, 0, 0, time.UTC)
text := []byte("Time: ")
text = t.AppendFormat(text, time.Kitchen)
fmt.Println(string(text))
}
package main
import (
"fmt"
"time"
)
func main() {
year2000 := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
year3000 := time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)
isYear2000BeforeYear3000 := year2000.Before(year3000) // True
isYear3000BeforeYear2000 := year3000.Before(year2000) // False
fmt.Printf("year2000.Before(year3000) = %v\n", isYear2000BeforeYear3000)
fmt.Printf("year3000.Before(year2000) = %v\n", isYear3000BeforeYear2000)
}
package main
import (
"fmt"
"time"
)
func main() {
d := time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC)
year, month, day := d.Date()
fmt.Printf("year = %v\n", year)
fmt.Printf("month = %v\n", month)
fmt.Printf("day = %v\n", day)
}
package main
import (
"fmt"
"time"
)
func main() {
d := time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC)
day := d.Day()
fmt.Printf("day = %v\n", day)
}
package main
import (
"fmt"
"time"
)
func main() {
secondsEastOfUTC := int((8 * time.Hour).Seconds())
beijing := time.FixedZone("Beijing Time", secondsEastOfUTC)
// Unlike the equal operator, Equal is aware that d1 and d2 are the
// same instant but in different time zones.
d1 := time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC)
d2 := time.Date(2000, 2, 1, 20, 30, 0, 0, beijing)
datesEqualUsingEqualOperator := d1 == d2
datesEqualUsingFunction := d1.Equal(d2)
fmt.Printf("datesEqualUsingEqualOperator = %v\n", datesEqualUsingEqualOperator)
fmt.Printf("datesEqualUsingFunction = %v\n", datesEqualUsingFunction)
}
package main
import (
"fmt"
"time"
)
func main() {
// Parse a time value from a string in the standard Unix format.
t, err := time.Parse(time.UnixDate, "Wed Feb 25 11:06:39 PST 2015")
if err != nil { // Always check errors even if they should not happen.
panic(err)
}
// time.Time's Stringer method is useful without any format.
fmt.Println("default format:", t)
// Predefined constants in the package implement common layouts.
fmt.Println("Unix format:", t.Format(time.UnixDate))
// The time zone attached to the time value affects its output.
fmt.Println("Same, in UTC:", t.UTC().Format(time.UnixDate))
// The rest of this function demonstrates the properties of the
// layout string used in the format.
// The layout string used by the Parse function and Format method
// shows by example how the reference time should be represented.
// We stress that one must show how the reference time is formatted,
// not a time of the user's choosing. Thus each layout string is a
// representation of the time stamp,
// Jan 2 15:04:05 2006 MST
// An easy way to remember this value is that it holds, when presented
// in this order, the values (lined up with the elements above):
// 1 2 3 4 5 6 -7
// There are some wrinkles illustrated below.
// Most uses of Format and Parse use constant layout strings such as
// the ones defined in this package, but the interface is flexible,
// as these examples show.
// Define a helper function to make the examples' output look nice.
do := func(name, layout, want string) {
got := t.Format(layout)
if want != got {
fmt.Printf("error: for %q got %q; expected %q\n", layout, got, want)
return
}
fmt.Printf("%-16s %q gives %q\n", name, layout, got)
}
// Print a header in our output.
fmt.Printf("\nFormats:\n\n")
// Simple starter examples.
do("Basic full date", "Mon Jan 2 15:04:05 MST 2006", "Wed Feb 25 11:06:39 PST 2015")
do("Basic short date", "2006/01/02", "2015/02/25")
// The hour of the reference time is 15, or 3PM. The layout can express
// it either way, and since our value is the morning we should see it as
// an AM time. We show both in one format string. Lower case too.
do("AM/PM", "3PM==3pm==15h", "11AM==11am==11h")
// When parsing, if the seconds value is followed by a decimal point
// and some digits, that is taken as a fraction of a second even if
// the layout string does not represent the fractional second.
// Here we add a fractional second to our time value used above.
t, err = time.Parse(time.UnixDate, "Wed Feb 25 11:06:39.1234 PST 2015")
if err != nil {
panic(err)
}
// It does not appear in the output if the layout string does not contain
// a representation of the fractional second.
do("No fraction", time.UnixDate, "Wed Feb 25 11:06:39 PST 2015")
// Fractional seconds can be printed by adding a run of 0s or 9s after
// a decimal point in the seconds value in the layout string.
// If the layout digits are 0s, the fractional second is of the specified
// width. Note that the output has a trailing zero.
do("0s for fraction", "15:04:05.00000", "11:06:39.12340")
// If the fraction in the layout is 9s, trailing zeros are dropped.
do("9s for fraction", "15:04:05.99999999", "11:06:39.1234")
}
package main
import (
"fmt"
"time"
)
func main() {
// Parse a time value from a string in the standard Unix format.
t, err := time.Parse(time.UnixDate, "Sat Mar 7 11:06:39 PST 2015")
if err != nil { // Always check errors even if they should not happen.
panic(err)
}
// Define a helper function to make the examples' output look nice.
do := func(name, layout, want string) {
got := t.Format(layout)
if want != got {
fmt.Printf("error: for %q got %q; expected %q\n", layout, got, want)
return
}
fmt.Printf("%-16s %q gives %q\n", name, layout, got)
}
// The predefined constant Unix uses an underscore to pad the day.
do("Unix", time.UnixDate, "Sat Mar 7 11:06:39 PST 2015")
// For fixed-width printing of values, such as the date, that may be one or
// two characters (7 vs. 07), use an _ instead of a space in the layout string.
// Here we print just the day, which is 2 in our layout string and 7 in our
// value.
do("No pad", "<2>", "<7>")
// An underscore represents a space pad, if the date only has one digit.
do("Spaces", "<_2>", "< 7>")
// A "0" indicates zero padding for single-digit values.
do("Zeros", "<02>", "<07>")
// If the value is already the right width, padding is not used.
// For instance, the second (05 in the reference time) in our value is 39,
// so it doesn't need padding, but the minutes (04, 06) does.
do("Suppressed pad", "04:05", "06:39")
}
package main
import (
"fmt"
"time"
)
func main() {
t := time.Date(0, 0, 0, 12, 15, 30, 918273645, time.UTC)
round := []time.Duration{
time.Nanosecond,
time.Microsecond,
time.Millisecond,
time.Second,
2 * time.Second,
time.Minute,
10 * time.Minute,
time.Hour,
}
for _, d := range round {
fmt.Printf("t.Round(%6s) = %s\n", d, t.Round(d).Format("15:04:05.999999999"))
}
}
package main
import (
"fmt"
"time"
)
func main() {
timeWithNanoseconds := time.Date(2000, 2, 1, 12, 13, 14, 15, time.UTC)
withNanoseconds := timeWithNanoseconds.String()
timeWithoutNanoseconds := time.Date(2000, 2, 1, 12, 13, 14, 0, time.UTC)
withoutNanoseconds := timeWithoutNanoseconds.String()
fmt.Printf("withNanoseconds = %v\n", string(withNanoseconds))
fmt.Printf("withoutNanoseconds = %v\n", string(withoutNanoseconds))
}
package main
import (
"fmt"
"time"
)
func main() {
start := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2000, 1, 1, 12, 0, 0, 0, time.UTC)
difference := end.Sub(start)
fmt.Printf("difference = %v\n", difference)
}
package main
import (
"fmt"
"time"
)
func main() {
t, _ := time.Parse("2006 Jan 02 15:04:05", "2012 Dec 07 12:15:30.918273645")
trunc := []time.Duration{
time.Nanosecond,
time.Microsecond,
time.Millisecond,
time.Second,
2 * time.Second,
time.Minute,
10 * time.Minute,
}
for _, d := range trunc {
fmt.Printf("t.Truncate(%5s) = %s\n", d, t.Truncate(d).Format("15:04:05.999999999"))
}
// To round to the last midnight in the local timezone, create a new Date.
midnight := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
_ = midnight
}
package main
import (
"fmt"
"time"
)
func main() {
// 1 billion seconds of Unix, three ways.
fmt.Println(time.Unix(1e9, 0).UTC()) // 1e9 seconds
fmt.Println(time.Unix(0, 1e18).UTC()) // 1e18 nanoseconds
fmt.Println(time.Unix(2e9, -1e18).UTC()) // 2e9 seconds - 1e18 nanoseconds
t := time.Date(2001, time.September, 9, 1, 46, 40, 0, time.UTC)
fmt.Println(t.Unix()) // seconds since 1970
fmt.Println(t.UnixNano()) // nanoseconds since 1970
}
Package-Level Type Names (total 15, in which 8 are exported)
A Location maps time instants to the zone in use at that time.
Typically, the Location represents the collection of time offsets
in use in a geographical area. For many Locations the time offset varies
depending on whether daylight savings time is in use at the time instant.
cacheEndint64
Most lookups will be for the current time.
To avoid the binary search through tx, keep a
static one-element cache that gives the correct
zone for the time when the Location was created.
if cacheStart <= t < cacheEnd,
lookup can return cacheZone.
The units for cacheStart and cacheEnd are seconds
since January 1, 1970 UTC, to match the argument
to lookup.
cacheZone*zone
The tzdata information can be followed by a string that describes
how to handle DST transitions not recorded in zoneTrans.
The format is the TZ environment variable without a colon; see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html.
Example string, for America/Los_Angeles: PST8PDT,M3.2.0,M11.1.0
namestringtx[]zoneTranszone[]zone
String returns a descriptive name for the time zone information,
corresponding to the name argument to LoadLocation or FixedZone.
firstZoneUsed reports whether the first zone is used by some
transition.
(*T) get() *Location
lookup returns information about the time zone in use at an
instant in time expressed as seconds since January 1, 1970 00:00:00 UTC.
The returned information gives the name of the zone (such as "CET"),
the start and end times bracketing sec when that zone is in effect,
the offset in seconds east of UTC (such as -5*60*60), and whether
the daylight savings is being observed at that time.
lookupFirstZone returns the index of the time zone to use for times
before the first transition time, or when there are no transition
times.
The reference implementation in localtime.c from
https://www.iana.org/time-zones/repository/releases/tzcode2013g.tar.gz
implements the following algorithm for these cases:
1) If the first zone is unused by the transitions, use it.
2) Otherwise, if there are transition times, and the first
transition is to a zone in daylight time, find the first
non-daylight-time zone before and closest to the first transition
zone.
3) Otherwise, use the first zone that is not daylight time, if
there is one.
4) Otherwise, use the first zone.
lookupName returns information about the time zone with
the given name (such as "EST") at the given pseudo-Unix time
(what the given time of day would be in UTC).
*T : fmt.Stringer
*T : context.stringer
*T : runtime.stringer
func FixedZone(name string, offset int) *Location
func LoadLocation(name string) (*Location, error)
func LoadLocationFromTZData(name string, data []byte) (*Location, error)
func Time.Location() *Location
func loadLocation(name string, sources []string) (z *Location, firstErr error)
func (*Location).get() *Location
func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time
func ParseInLocation(layout, value string, loc *Location) (Time, error)
func Time.In(loc *Location) Time
func parse(layout, value string, defaultLocation, local *Location) (Time, error)
func (*Time).setLoc(loc *Location)
var Local *Location
var UTC *Location
var localLoc
var utcLoc
A Ticker holds a channel that delivers ``ticks'' of a clock
at intervals.
C<-chan TimerruntimeTimer
Reset stops a ticker and resets its period to the specified duration.
The next tick will arrive after the new period elapses.
Stop turns off a ticker. After Stop, no more ticks will be sent.
Stop does not close the channel, to prevent a concurrent goroutine
reading from the channel from seeing an erroneous "tick".
func NewTicker(d Duration) *Ticker
A Time represents an instant in time with nanosecond precision.
Programs using times should typically store and pass them as values,
not pointers. That is, time variables and struct fields should be of
type time.Time, not *time.Time.
A Time value can be used by multiple goroutines simultaneously except
that the methods GobDecode, UnmarshalBinary, UnmarshalJSON and
UnmarshalText are not concurrency-safe.
Time instants can be compared using the Before, After, and Equal methods.
The Sub method subtracts two instants, producing a Duration.
The Add method adds a Time and a Duration, producing a Time.
The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.
As this time is unlikely to come up in practice, the IsZero method gives
a simple way of detecting a time that has not been initialized explicitly.
Each Time has associated with it a Location, consulted when computing the
presentation form of the time, such as in the Format, Hour, and Year methods.
The methods Local, UTC, and In return a Time with a specific location.
Changing the location in this way changes only the presentation; it does not
change the instant in time being denoted and therefore does not affect the
computations described in earlier paragraphs.
Representations of a Time value saved by the GobEncode, MarshalBinary,
MarshalJSON, and MarshalText methods store the Time.Location's offset, but not
the location name. They therefore lose information about Daylight Saving Time.
In addition to the required “wall clock” reading, a Time may contain an optional
reading of the current process's monotonic clock, to provide additional precision
for comparison or subtraction.
See the “Monotonic Clocks” section in the package documentation for details.
Note that the Go == operator compares not just the time instant but also the
Location and the monotonic clock reading. Therefore, Time values should not
be used as map or database keys without first guaranteeing that the
identical Location has been set for all values, which can be achieved
through use of the UTC or Local method, and that the monotonic clock reading
has been stripped by setting t = t.Round(0). In general, prefer t.Equal(u)
to t == u, since t.Equal uses the most accurate comparison available and
correctly handles the case when only one of its arguments has a monotonic
clock reading.
extint64
loc specifies the Location that should be used to
determine the minute, hour, month, day, and year
that correspond to this Time.
The nil location means UTC.
All UTC times are represented with loc==nil, never loc==&utcLoc.
wall and ext encode the wall time seconds, wall time nanoseconds,
and optional monotonic clock reading in nanoseconds.
From high to low bit position, wall encodes a 1-bit flag (hasMonotonic),
a 33-bit seconds field, and a 30-bit wall time nanoseconds field.
The nanoseconds field is in the range [0, 999999999].
If the hasMonotonic bit is 0, then the 33-bit field must be zero
and the full signed 64-bit wall seconds since Jan 1 year 1 is stored in ext.
If the hasMonotonic bit is 1, then the 33-bit field holds a 33-bit
unsigned wall seconds since Jan 1 year 1885, and ext holds a
signed 64-bit monotonic clock reading, nanoseconds since process start.
Add returns the time t+d.
AddDate returns the time corresponding to adding the
given number of years, months, and days to t.
For example, AddDate(-1, 2, 3) applied to January 1, 2011
returns March 4, 2010.
AddDate normalizes its result in the same way that Date does,
so, for example, adding one month to October 31 yields
December 1, the normalized form for November 31.
After reports whether the time instant t is after u.
AppendFormat is like Format but appends the textual
representation to b and returns the extended buffer.
Before reports whether the time instant t is before u.
Clock returns the hour, minute, and second within the day specified by t.
Date returns the year, month, and day in which t occurs.
Day returns the day of the month specified by t.
Equal reports whether t and u represent the same time instant.
Two times can be equal even if they are in different locations.
For example, 6:00 +0200 and 4:00 UTC are Equal.
See the documentation on the Time type for the pitfalls of using == with
Time values; most code should use Equal instead.
Format returns a textual representation of the time value formatted
according to layout, which defines the format by showing how the reference
time, defined to be
Mon Jan 2 15:04:05 -0700 MST 2006
would be displayed if it were the value; it serves as an example of the
desired output. The same display rules will then be applied to the time
value.
A fractional second is represented by adding a period and zeros
to the end of the seconds section of layout string, as in "15:04:05.000"
to format a time stamp with millisecond precision.
Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard
and convenient representations of the reference time. For more information
about the formats and the definition of the reference time, see the
documentation for ANSIC and the other constants defined by this package.
GobDecode implements the gob.GobDecoder interface.
GobEncode implements the gob.GobEncoder interface.
Hour returns the hour within the day specified by t, in the range [0, 23].
ISOWeek returns the ISO 8601 year and week number in which t occurs.
Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to
week 52 or 53 of year n-1, and Dec 29 to Dec 31 might belong to week 1
of year n+1.
In returns a copy of t representing the same time instant, but
with the copy's location information set to loc for display
purposes.
In panics if loc is nil.
IsZero reports whether t represents the zero time instant,
January 1, year 1, 00:00:00 UTC.
Local returns t with the location set to local time.
Location returns the time zone information associated with t.
MarshalBinary implements the encoding.BinaryMarshaler interface.
MarshalJSON implements the json.Marshaler interface.
The time is a quoted string in RFC 3339 format, with sub-second precision added if present.
MarshalText implements the encoding.TextMarshaler interface.
The time is formatted in RFC 3339 format, with sub-second precision added if present.
Minute returns the minute offset within the hour specified by t, in the range [0, 59].
Month returns the month of the year specified by t.
Nanosecond returns the nanosecond offset within the second specified by t,
in the range [0, 999999999].
Round returns the result of rounding t to the nearest multiple of d (since the zero time).
The rounding behavior for halfway values is to round up.
If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
Round operates on the time as an absolute duration since the
zero time; it does not operate on the presentation form of the
time. Thus, Round(Hour) may return a time with a non-zero
minute, depending on the time's Location.
Second returns the second offset within the minute specified by t, in the range [0, 59].
String returns the time formatted using the format string
"2006-01-02 15:04:05.999999999 -0700 MST"
If the time has a monotonic clock reading, the returned string
includes a final field "m=±<value>", where value is the monotonic
clock reading formatted as a decimal number of seconds.
The returned string is meant for debugging; for a stable serialized
representation, use t.MarshalText, t.MarshalBinary, or t.Format
with an explicit format string.
Sub returns the duration t-u. If the result exceeds the maximum (or minimum)
value that can be stored in a Duration, the maximum (or minimum) duration
will be returned.
To compute t-d for a duration d, use t.Add(-d).
Truncate returns the result of rounding t down to a multiple of d (since the zero time).
If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
Truncate operates on the time as an absolute duration since the
zero time; it does not operate on the presentation form of the
time. Thus, Truncate(Hour) may return a time with a non-zero
minute, depending on the time's Location.
UTC returns t with the location set to UTC.
Unix returns t as a Unix time, the number of seconds elapsed
since January 1, 1970 UTC. The result does not depend on the
location associated with t.
Unix-like operating systems often record time as a 32-bit
count of seconds, but since the method here returns a 64-bit
value it is valid for billions of years into the past or future.
UnixNano returns t as a Unix time, the number of nanoseconds elapsed
since January 1, 1970 UTC. The result is undefined if the Unix time
in nanoseconds cannot be represented by an int64 (a date before the year
1678 or after 2262). Note that this means the result of calling UnixNano
on the zero Time is undefined. The result does not depend on the
location associated with t.
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
UnmarshalJSON implements the json.Unmarshaler interface.
The time is expected to be a quoted string in RFC 3339 format.
UnmarshalText implements the encoding.TextUnmarshaler interface.
The time is expected to be in RFC 3339 format.
Weekday returns the day of the week specified by t.
Year returns the year in which t occurs.
YearDay returns the day of the year specified by t, in the range [1,365] for non-leap years,
and [1,366] in leap years.
Zone computes the time zone in effect at time t, returning the abbreviated
name of the zone (such as "CET") and its offset in seconds east of UTC.
abs returns the time t as an absolute time, adjusted by the zone offset.
It is called when computing a presentation property like Month or Hour.
addSec adds d seconds to the time.
date computes the year, day of year, and when full=true,
the month and day in which t occurs.
locabs is a combination of the Zone and abs methods,
extracting both return values from a single zone lookup.
mono returns t's monotonic clock reading.
It returns 0 for a missing reading.
This function is used only for testing,
so it's OK that technically 0 is a valid
monotonic clock reading as well.
nsec returns the time's nanoseconds.
sec returns the time's seconds since Jan 1 year 1.
setLoc sets the location associated with the time.
setMono sets the monotonic clock reading in t.
If t cannot hold a monotonic clock reading,
because its wall time is too large,
setMono is a no-op.
stripMono strips the monotonic clock reading in t.
unixSec returns the time's seconds since Jan 1 1970 (Unix time).
T : encoding.BinaryMarshaler
*T : encoding.BinaryUnmarshaler
T : encoding.TextMarshaler
*T : encoding.TextUnmarshaler
T : encoding/json.Marshaler
*T : encoding/json.Unmarshaler
T : fmt.Stringer
T : context.stringer
*T : crypto/hmac.marshalable
T : runtime.stringer
func After(d Duration) <-chan Time
func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time
func Now() Time
func Parse(layout, value string) (Time, error)
func ParseInLocation(layout, value string, loc *Location) (Time, error)
func Tick(d Duration) <-chan Time
func Unix(sec int64, nsec int64) Time
func Time.Add(d Duration) Time
func Time.AddDate(years int, months int, days int) Time
func Time.In(loc *Location) Time
func Time.Local() Time
func Time.Round(d Duration) Time
func Time.Truncate(d Duration) Time
func Time.UTC() Time
func context.Context.Deadline() (deadline Time, ok bool)
func github.com/neo4j/neo4j-go-driver/v4/neo4j/db.Connection.Birthdate() Time
func github.com/neo4j/neo4j-go-driver/v4/neo4j/dbtype.Date.Time() Time
func github.com/neo4j/neo4j-go-driver/v4/neo4j/dbtype.LocalDateTime.Time() Time
func github.com/neo4j/neo4j-go-driver/v4/neo4j/dbtype.LocalTime.Time() Time
func github.com/neo4j/neo4j-go-driver/v4/neo4j/dbtype.Time.Time() Time
func io/fs.FileInfo.ModTime() Time
func os.FileInfo.ModTime() Time
func parse(layout, value string, defaultLocation, local *Location) (Time, error)
func unixTime(sec int64, nsec int32) Time
func crypto/tls.(*Config).time() Time
func encoding/asn1.parseGeneralizedTime(bytes []byte) (ret Time, err error)
func encoding/asn1.parseUTCTime(bytes []byte) (ret Time, err error)
func net.minNonzeroTime(a, b Time) Time
func net.partialDeadline(now, deadline Time, addrsRemaining int) (Time, error)
func net.stat(name string) (mtime Time, size int64, err error)
func net.(*Dialer).deadline(ctx context.Context, now Time) (earliest Time)
func os.atime(fi os.FileInfo) Time
func os.timespecToTime(ts syscall.Timespec) Time
func Since(t Time) Duration
func Until(t Time) Duration
func Time.After(u Time) bool
func Time.Before(u Time) bool
func Time.Equal(u Time) bool
func Time.Sub(u Time) Duration
func context.WithDeadline(parent context.Context, d Time) (context.Context, context.CancelFunc)
func crypto/tls.(*Conn).SetDeadline(t Time) error
func crypto/tls.(*Conn).SetReadDeadline(t Time) error
func crypto/tls.(*Conn).SetWriteDeadline(t Time) error
func crypto/x509.(*Certificate).CreateCRL(rand io.Reader, priv interface{}, revokedCerts []pkix.RevokedCertificate, now, expiry Time) (crlBytes []byte, err error)
func crypto/x509/pkix.(*CertificateList).HasExpired(now Time) bool
func github.com/neo4j/neo4j-go-driver/v4/neo4j.DateOf(t Time) neo4j.Date
func github.com/neo4j/neo4j-go-driver/v4/neo4j.LocalDateTimeOf(t Time) neo4j.LocalDateTime
func github.com/neo4j/neo4j-go-driver/v4/neo4j.LocalTimeOf(t Time) neo4j.LocalTime
func github.com/neo4j/neo4j-go-driver/v4/neo4j.OffsetTimeOf(t Time) neo4j.OffsetTime
func internal/poll.(*FD).SetDeadline(t Time) error
func internal/poll.(*FD).SetReadDeadline(t Time) error
func internal/poll.(*FD).SetWriteDeadline(t Time) error
func net.Conn.SetDeadline(t Time) error
func net.Conn.SetReadDeadline(t Time) error
func net.Conn.SetWriteDeadline(t Time) error
func net.PacketConn.SetDeadline(t Time) error
func net.PacketConn.SetReadDeadline(t Time) error
func net.PacketConn.SetWriteDeadline(t Time) error
func net.(*TCPListener).SetDeadline(t Time) error
func net.(*UnixListener).SetDeadline(t Time) error
func os.Chtimes(name string, atime Time, mtime Time) error
func os.Chtimes(name string, atime Time, mtime Time) error
func os.(*File).SetDeadline(t Time) error
func os.(*File).SetReadDeadline(t Time) error
func os.(*File).SetWriteDeadline(t Time) error
func vendor/golang.org/x/crypto/cryptobyte.(*Builder).AddASN1GeneralizedTime(t Time)
func vendor/golang.org/x/crypto/cryptobyte.(*String).ReadASN1GeneralizedTime(out *Time) bool
func div(t Time, d Duration) (qmod2 int, r Duration)
func encoding/asn1.appendGeneralizedTime(dst []byte, t Time) (ret []byte, err error)
func encoding/asn1.appendTimeCommon(dst []byte, t Time) []byte
func encoding/asn1.appendUTCTime(dst []byte, t Time) (ret []byte, err error)
func encoding/asn1.makeGeneralizedTime(t Time) (e asn1.encoder, err error)
func encoding/asn1.makeUTCTime(t Time) (e asn1.encoder, err error)
func encoding/asn1.outsideUTCRange(t Time) bool
func github.com/neo4j/neo4j-go-driver/v4/neo4j/internal/pool.(*Pool).removeIdleOlderThanOnServer(serverName string, now Time, maxAge Duration)
func github.com/neo4j/neo4j-go-driver/v4/neo4j/internal/pool.(*Pool).unreg(serverName string, c db.Connection, now Time)
func internal/poll.setDeadlineImpl(fd *poll.FD, t Time, mode int) error
func net.minNonzeroTime(a, b Time) Time
func net.partialDeadline(now, deadline Time, addrsRemaining int) (Time, error)
func net.(*Dialer).deadline(ctx context.Context, now Time) (earliest Time)
func os.(*File).setDeadline(t Time) error
func os.(*File).setReadDeadline(t Time) error
func os.(*File).setWriteDeadline(t Time) error
var net.aLongTimeAgo
var net.noDeadline
The Timer type represents a single event.
When the Timer expires, the current time will be sent on C,
unless the Timer was created by AfterFunc.
A Timer must be created with NewTimer or AfterFunc.
C<-chan TimerruntimeTimer
Reset changes the timer to expire after duration d.
It returns true if the timer had been active, false if the timer had
expired or been stopped.
For a Timer created with NewTimer, Reset should be invoked only on
stopped or expired timers with drained channels.
If a program has already received a value from t.C, the timer is known
to have expired and the channel drained, so t.Reset can be used directly.
If a program has not yet received a value from t.C, however,
the timer must be stopped and—if Stop reports that the timer expired
before being stopped—the channel explicitly drained:
if !t.Stop() {
<-t.C
}
t.Reset(d)
This should not be done concurrent to other receives from the Timer's
channel.
Note that it is not possible to use Reset's return value correctly, as there
is a race condition between draining the channel and the new timer expiring.
Reset should always be invoked on stopped or expired channels, as described above.
The return value exists to preserve compatibility with existing programs.
For a Timer created with AfterFunc(d, f), Reset either reschedules
when f will run, in which case Reset returns true, or schedules f
to run again, in which case it returns false.
When Reset returns false, Reset neither waits for the prior f to
complete before returning nor does it guarantee that the subsequent
goroutine running f does not run concurrently with the prior
one. If the caller needs to know whether the prior execution of
f is completed, it must coordinate with f explicitly.
Stop prevents the Timer from firing.
It returns true if the call stops the timer, false if the timer has already
expired or been stopped.
Stop does not close the channel, to prevent a read from the channel succeeding
incorrectly.
To ensure the channel is empty after a call to Stop, check the
return value and drain the channel.
For example, assuming the program has not received from t.C already:
if !t.Stop() {
<-t.C
}
This cannot be done concurrent to other receives from the Timer's
channel or other calls to the Timer's Stop method.
For a timer created with AfterFunc(d, f), if t.Stop returns false, then the timer
has already expired and the function f has been started in its own goroutine;
Stop does not wait for f to complete before returning.
If the caller needs to know whether f is completed, it must coordinate
with f explicitly.
func AfterFunc(d Duration, f func()) *Timer
func NewTimer(d Duration) *Timer
A zone represents a single time zone such as CET.
// is this zone Daylight Savings Time?
// abbreviated name, "CET"
// seconds east of UTC
func findZone(zones []zone, name string, offset int, isDST bool) int
A zoneTrans represents a single time zone transition.
// the index of the zone that goes into effect at that time
// ignored - no idea what these mean
// ignored - no idea what these mean
// transition time, in seconds since 1970 GMT
Package-Level Functions (total 81, in which 17 are exported)
After waits for the duration to elapse and then sends the current time
on the returned channel.
It is equivalent to NewTimer(d).C.
The underlying Timer is not recovered by the garbage collector
until the timer fires. If efficiency is a concern, use NewTimer
instead and call Timer.Stop if the timer is no longer needed.
AfterFunc waits for the duration to elapse and then calls f
in its own goroutine. It returns a Timer that can
be used to cancel the call using its Stop method.
Date returns the Time corresponding to
yyyy-mm-dd hh:mm:ss + nsec nanoseconds
in the appropriate zone for that time in the given location.
The month, day, hour, min, sec, and nsec values may be outside
their usual ranges and will be normalized during the conversion.
For example, October 32 converts to November 1.
A daylight savings time transition skips or repeats times.
For example, in the United States, March 13, 2011 2:15am never occurred,
while November 6, 2011 1:15am occurred twice. In such cases, the
choice of time zone, and therefore the time, is not well-defined.
Date returns a time that is correct in one of the two zones involved
in the transition, but it does not guarantee which.
Date panics if loc is nil.
FixedZone returns a Location that always uses
the given zone name and offset (seconds east of UTC).
LoadLocation returns the Location with the given name.
If the name is "" or "UTC", LoadLocation returns UTC.
If the name is "Local", LoadLocation returns Local.
Otherwise, the name is taken to be a location name corresponding to a file
in the IANA Time Zone database, such as "America/New_York".
The time zone database needed by LoadLocation may not be
present on all systems, especially non-Unix systems.
LoadLocation looks in the directory or uncompressed zip file
named by the ZONEINFO environment variable, if any, then looks in
known installation locations on Unix systems,
and finally looks in $GOROOT/lib/time/zoneinfo.zip.
LoadLocationFromTZData returns a Location with the given name
initialized from the IANA Time Zone database-formatted data.
The data should be in the format of a standard IANA time zone file
(for example, the content of /etc/localtime on Unix systems).
NewTicker returns a new Ticker containing a channel that will send
the time on the channel after each tick. The period of the ticks is
specified by the duration argument. The ticker will adjust the time
interval or drop ticks to make up for slow receivers.
The duration d must be greater than zero; if not, NewTicker will
panic. Stop the ticker to release associated resources.
NewTimer creates a new Timer that will send
the current time on its channel after at least duration d.
Now returns the current local time.
Parse parses a formatted string and returns the time value it represents.
The layout defines the format by showing how the reference time,
defined to be
Mon Jan 2 15:04:05 -0700 MST 2006
would be interpreted if it were the value; it serves as an example of
the input format. The same interpretation will then be made to the
input string.
Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard
and convenient representations of the reference time. For more information
about the formats and the definition of the reference time, see the
documentation for ANSIC and the other constants defined by this package.
Also, the executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Elements omitted from the value are assumed to be zero or, when
zero is impossible, one, so parsing "3:04pm" returns the time
corresponding to Jan 1, year 0, 15:04:00 UTC (note that because the year is
0, this time is before the zero Time).
Years must be in the range 0000..9999. The day of the week is checked
for syntax but it is otherwise ignored.
For layouts specifying the two-digit year 06, a value NN >= 69 will be treated
as 19NN and a value NN < 69 will be treated as 20NN.
In the absence of a time zone indicator, Parse returns a time in UTC.
When parsing a time with a zone offset like -0700, if the offset corresponds
to a time zone used by the current location (Local), then Parse uses that
location and zone in the returned time. Otherwise it records the time as
being in a fabricated location with time fixed at the given zone offset.
When parsing a time with a zone abbreviation like MST, if the zone abbreviation
has a defined offset in the current location, then that offset is used.
The zone abbreviation "UTC" is recognized as UTC regardless of location.
If the zone abbreviation is unknown, Parse records the time as being
in a fabricated location with the given zone abbreviation and a zero offset.
This choice means that such a time can be parsed and reformatted with the
same layout losslessly, but the exact instant used in the representation will
differ by the actual zone offset. To avoid such problems, prefer time layouts
that use a numeric zone offset, or use ParseInLocation.
ParseDuration parses a duration string.
A duration string is a possibly signed sequence of
decimal numbers, each with optional fraction and a unit suffix,
such as "300ms", "-1.5h" or "2h45m".
Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
ParseInLocation is like Parse but differs in two important ways.
First, in the absence of time zone information, Parse interprets a time as UTC;
ParseInLocation interprets the time as in the given location.
Second, when given a zone offset or abbreviation, Parse tries to match it
against the Local location; ParseInLocation uses the given location.
Since returns the time elapsed since t.
It is shorthand for time.Now().Sub(t).
Sleep pauses the current goroutine for at least the duration d.
A negative or zero duration causes Sleep to return immediately.
Tick is a convenience wrapper for NewTicker providing access to the ticking
channel only. While Tick is useful for clients that have no need to shut down
the Ticker, be aware that without a way to shut it down the underlying
Ticker cannot be recovered by the garbage collector; it "leaks".
Unlike NewTicker, Tick will return nil if d <= 0.
Unix returns the local Time corresponding to the given Unix time,
sec seconds and nsec nanoseconds since January 1, 1970 UTC.
It is valid to pass nsec outside the range [0, 999999999].
Not all sec values have a corresponding time value. One such
value is 1<<63-1 (the largest int64 value).
Until returns the duration until t.
It is shorthand for t.Sub(time.Now()).
absClock is like clock but operates on an absolute time.
absDate is like date but operates on an absolute time.
absWeekday is like Weekday but operates on an absolute time.
appendInt appends the decimal form of x to b and returns the result.
If the decimal form (excluding sign) is shorter than width, the result is padded with leading 0's.
Duplicates functionality in strconv, but avoids dependency.
Duplicates functionality in strconv, but avoids dependency.
daysSinceEpoch takes a year and returns the number of days from
the absolute epoch to the start of that year.
This is basically (year - zeroYear) * 365, but accounting for leap days.
div divides t by d and returns the quotient parity and remainder.
We don't use the quotient parity anymore (round half up instead of round to even)
but it's still here in case we change our minds.
fmtFrac formats the fraction of v/10**prec (e.g., ".12345") into the
tail of buf, omitting trailing zeros. It omits the decimal
point too when the fraction is 0. It returns the index where the
output bytes begin and the value v/10**prec.
fmtInt formats v into the tail of buf.
It returns the index where the output begins.
formatNano appends a fractional second, as nanoseconds, to b
and returns the result.
get2 returns the little-endian 16-bit value in b.
get4 returns the little-endian 32-bit value in b.
getnum parses s[0:1] or s[0:2] (fixed forces s[0:2])
as a decimal integer and returns the integer and the
remainder of the string.
getnum3 parses s[0:1], s[0:2], or s[0:3] (fixed forces s[0:3])
as a decimal integer and returns the integer and the remainder
of the string.
leadingFraction consumes the leading [0-9]* from s.
It is used only for fractions, so does not return an error on overflow,
it just stops accumulating precision.
leadingInt consumes the leading [0-9]* from s.
lessThanHalf reports whether x+x < y but avoids overflow,
assuming x and y are both positive (Duration is signed).
loadLocation returns the Location with the given name from one of
the specified sources. See loadTzinfo for a list of supported sources.
The first timezone data matching the given name that is successfully loaded
and parsed is returned as a Location.
loadTzinfo returns the time zone information of the time zone
with the given name, from a given source. A source may be a
timezone database directory, tzdata database file or an uncompressed
zip file, containing the contents of such a directory.
loadTzinfoFromDirOrZip returns the contents of the file with the given name
in dir. dir can either be an uncompressed zip file, or a directory.
loadTzinfoFromZip returns the contents of the file with the given name
in the given uncompressed zip file.
parseGMT parses a GMT time zone. The input string is known to start "GMT".
The function checks whether that is followed by a sign and a number in the
range -23 through +23 excluding zero.
parseSignedOffset parses a signed timezone offset (e.g. "+03" or "-04").
The function checks for a signed number in the range -23 through +23 excluding zero.
Returns length of the found offset string or 0 otherwise
parseTimeZone parses a time zone string and returns its length. Time zones
are human-generated and unpredictable. We can't do precise error checking.
On the other hand, for a correct parse there must be a time zone at the
beginning of the string, so it's almost always true that there's one
there. We look at the beginning of the string for a run of upper-case letters.
If there are more than 5, it's an error.
If there are 4 or 5 and the last is a T, it's a time zone.
If there are 3, it's a time zone.
Otherwise, other than special cases, it's not a time zone.
GMT is special because it can have an hour offset.
readFile reads and returns the content of the named file.
It is a trivial implementation of os.ReadFile, reimplemented
here to avoid depending on io/ioutil or os.
It returns an error if name exceeds maxFileSize bytes.
registerLoadFromEmbeddedTZData is called by the time/tzdata package,
if it is imported.
skip removes the given prefix from value,
treating runs of space characters as equivalent.
startsWithLowerCase reports whether the string has a lower-case letter at the beginning.
Its purpose is to prevent matching strings like "Month" when looking for "Mon".
tzruleTime takes a year, a rule, and a timezone offset,
and returns the number of seconds since the start of the year
that the rule takes effect.
tzset takes a timezone string like the one found in the TZ environment
variable, the end of the last time zone transition expressed as seconds
since January 1, 1970 00:00:00 UTC, and a time expressed the same way.
We call this a tzset string since in C the function tzset reads TZ.
The return values are as for lookup, plus ok which reports whether the
parse succeeded.
tzsetName returns the timezone name at the start of the tzset string s,
and the remainder of s, and reports whether the parsing is OK.
tzsetNum parses a number from a tzset string.
It returns the number, and the remainder of the string, and reports success.
The number must be between min and max.
tzsetOffset returns the timezone offset at the start of the tzset string s,
and the remainder of s, and reports whether the parsing is OK.
The timezone offset is returned as a number of seconds.
tzsetRule parses a rule from a tzset string.
It returns the rule, and the remainder of the string, and reports success.
when is a helper function for setting the 'when' field of a runtimeTimer.
It returns what the time will be, in nanoseconds, Duration d in the future.
If d is negative, it is ignored. If the returned value would be less than
zero because of an overflow, MaxInt64 is returned.
Package-Level Variables (total 23, in which 2 are exported)
Local represents the system's local time zone.
On Unix systems, Local consults the TZ environment
variable to find the time zone to use. No TZ means
use the system default /etc/localtime.
TZ="" means use UTC.
TZ="foo" means use file foo in the system timezone directory.
UTC represents Universal Coordinated Time (UTC).
Never printed, just needs to be non-nil for return by atoi.
daysBefore[m] counts the number of days in a non-leap year
before month m begins. There is an entry for m=12, counting
the number of days before January of next year (365).
loadFromEmbeddedTZData is used to load a specific tzdata file
from tzdata information embedded in the binary itself.
This is set when the time/tzdata package is imported,
via registerLoadFromEmbeddedTzdata.
loadTzinfoFromTzdata returns the time zone information of the time zone
with the given name, from a tzdata database file as they are typically
found on android.
localLoc is separate so that initLocal can initialize
it even if a client has changed Local.
Monotonic times are reported as offsets from startNano.
We initialize startNano to runtimeNano() - 1 so that on systems where
monotonic time resolution is fairly low (e.g. Windows 2008
which appears to have a default resolution of 15ms),
we avoid ever reporting a monotonic time of 0.
(Callers may want to use 0 as "time not set".)
std0x records the std values for "01", "02", ..., "06".
Many systems use /usr/share/zoneinfo, Solaris 2 has
/usr/share/lib/zoneinfo, IRIX 6 has /usr/lib/locale/TZ.
Package-Level Constants (total 111, in which 40 are exported)
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
Common durations. There is no definition for units of Day or larger
to avoid confusion across daylight savings time zone transitions.
To count the number of units in a Duration, divide:
second := time.Second
fmt.Print(int64(second/time.Millisecond)) // prints 1000
To convert an integer number of units to a Duration, multiply:
seconds := 10
fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
Common durations. There is no definition for units of Day or larger
to avoid confusion across daylight savings time zone transitions.
To count the number of units in a Duration, divide:
second := time.Second
fmt.Print(int64(second/time.Millisecond)) // prints 1000
To convert an integer number of units to a Duration, multiply:
seconds := 10
fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
Common durations. There is no definition for units of Day or larger
to avoid confusion across daylight savings time zone transitions.
To count the number of units in a Duration, divide:
second := time.Second
fmt.Print(int64(second/time.Millisecond)) // prints 1000
To convert an integer number of units to a Duration, multiply:
seconds := 10
fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
Common durations. There is no definition for units of Day or larger
to avoid confusion across daylight savings time zone transitions.
To count the number of units in a Duration, divide:
second := time.Second
fmt.Print(int64(second/time.Millisecond)) // prints 1000
To convert an integer number of units to a Duration, multiply:
seconds := 10
fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
Common durations. There is no definition for units of Day or larger
to avoid confusion across daylight savings time zone transitions.
To count the number of units in a Duration, divide:
second := time.Second
fmt.Print(int64(second/time.Millisecond)) // prints 1000
To convert an integer number of units to a Duration, multiply:
seconds := 10
fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
Common durations. There is no definition for units of Day or larger
to avoid confusion across daylight savings time zone transitions.
To count the number of units in a Duration, divide:
second := time.Second
fmt.Print(int64(second/time.Millisecond)) // prints 1000
To convert an integer number of units to a Duration, multiply:
seconds := 10
fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700,
the reference time can be thought of as
01/02 03:04:05PM '06 -0700
To define your own format, write down what the reference time would look
like formatted your way; see the values of constants like ANSIC,
StampMicro or Kitchen for examples. The model is to demonstrate what the
reference time looks like so that the Format and Parse methods can apply
the same transformation to a general time value.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
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.
A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to
the given number of decimal places, with trailing zeros removed.
When parsing (only), the input may contain a fractional second
field immediately after the seconds field, even if the layout does not
signify its presence. In that case a decimal point followed by a maximal
series of digits is parsed as a fractional second.
Numeric time zone offsets format as follows:
-0700 ±hhmm
-07:00 ±hh:mm
-07 ±hh
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
Z07 Z or ±hh
The recognized day of week formats are "Mon" and "Monday".
The recognized month formats are "Jan" and "January".
The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded
day of month. The formats __2 and 002 are space-padded and zero-padded
three-character day of year; there is no unpadded day of year format.
Text in the format string that is not recognized as part of the reference
time is echoed verbatim during Format and expected to appear verbatim
in the input to Parse.
The executable example for Time.Format demonstrates the working
of the layout string in detail and is a good reference.
Note that the RFC822, RFC850, and RFC1123 formats should be applied
only to local times. Applying them to UTC times will use "UTC" as the
time zone abbreviation, while strictly speaking those RFCs require the
use of "GMT" in that case.
In general RFC1123Z should be used instead of RFC1123 for servers
that insist on that format, and RFC3339 should be preferred for new protocols.
RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting;
when used with time.Parse they do not accept all the time formats
permitted by the RFCs and they do accept time formats not formally defined.
The RFC3339Nano format removes trailing zeros from the seconds field
and thus may not sort correctly once formatted.
Offsets to convert between internal and absolute or Unix times.
The unsigned zero year for internal calculations.
Must be 1 mod 400, and times before it will not compute correctly,
but otherwise can be changed at will.
alpha and omega are the beginning and end of time for zone
transitions.
The pages are generated with Goldsv0.4.2. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.