mirror of
https://github.com/golang/go
synced 2024-11-18 20:04:52 -07:00
time: standard time doc fix and format example
This fixes the incorrect unix timestamp of the standard time and adds an example for (Time) Format to clarify how timezones work in format strings. Fixes #4364. R=golang-dev, remyoudompheng, kevlar, rsc CC=golang-dev https://golang.org/cl/7069046
This commit is contained in:
parent
a61dcef232
commit
657168fb17
@ -57,6 +57,16 @@ func ExampleDate() {
|
|||||||
// Output: Go launched at 2009-11-10 15:00:00 -0800 PST
|
// Output: Go launched at 2009-11-10 15:00:00 -0800 PST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleTime_Format() {
|
||||||
|
const format = "Jan 2, 2006 at 3:04pm (MST)"
|
||||||
|
t := time.Date(2009, time.November, 10, 15, 0, 0, 0, time.Local)
|
||||||
|
fmt.Println(t.Format(format))
|
||||||
|
fmt.Println(t.UTC().Format(format))
|
||||||
|
// Output:
|
||||||
|
// Nov 10, 2009 at 3:00pm (PST)
|
||||||
|
// Nov 10, 2009 at 11:00pm (UTC)
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleTime_Round() {
|
func ExampleTime_Round() {
|
||||||
t := time.Date(0, 0, 0, 12, 15, 30, 918273645, time.UTC)
|
t := time.Date(0, 0, 0, 12, 15, 30, 918273645, time.UTC)
|
||||||
round := []time.Duration{
|
round := []time.Duration{
|
||||||
|
@ -9,7 +9,7 @@ import "errors"
|
|||||||
// These are predefined layouts for use in Time.Format.
|
// These are predefined layouts for use in Time.Format.
|
||||||
// The standard time used in the layouts is:
|
// The standard time used in the layouts is:
|
||||||
// Mon Jan 2 15:04:05 MST 2006
|
// Mon Jan 2 15:04:05 MST 2006
|
||||||
// which is Unix time 1136243045. Since MST is GMT-0700,
|
// which is Unix time 1136239445. Since MST is GMT-0700,
|
||||||
// the standard time can be thought of as
|
// the standard time can be thought of as
|
||||||
// 01/02 03:04:05PM '06 -0700
|
// 01/02 03:04:05PM '06 -0700
|
||||||
// To define your own format, write down what the standard time would look
|
// To define your own format, write down what the standard time would look
|
||||||
|
Loading…
Reference in New Issue
Block a user