aboutsummaryrefslogtreecommitdiff
path: root/src/time/example_test.go
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-04-26 23:55:11 +0000
committerGopher Robot <gobot@golang.org>2022-04-27 00:11:22 +0000
commit24b570354caee33d4fb3934ce7ef1cc97fb403fd (patch)
tree38f5b36ca7fb2e020c0869e7976ac693af3a8643 /src/time/example_test.go
parent68b655f2b91c4407ccd781271039857e0d332989 (diff)
downloadgo-24b570354caee33d4fb3934ce7ef1cc97fb403fd.tar.gz
go-24b570354caee33d4fb3934ce7ef1cc97fb403fd.zip
time: document hhmmss formats
Fixes #52516 Change-Id: I173fdb09c245563e09be4e1aacfd374c3a764d74 GitHub-Last-Rev: 14a81e50616e0f268fee9323d0621de861885475 GitHub-Pull-Request: golang/go#52538 Reviewed-on: https://go-review.googlesource.com/c/go/+/402058 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/time/example_test.go')
-rw-r--r--src/time/example_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index ec2259b1ba..059c6310a6 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -212,6 +212,11 @@ func ExampleTime_Format() {
panic(err)
}
+ tz, err := time.LoadLocation("Asia/Shanghai")
+ 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)
@@ -221,6 +226,10 @@ func ExampleTime_Format() {
// The time zone attached to the time value affects its output.
fmt.Println("Same, in UTC:", t.UTC().Format(time.UnixDate))
+ fmt.Println("in Shanghai with seconds:", t.In(tz).Format("2006-01-02T15:04:05 -070000"))
+
+ fmt.Println("in Shanghai with colon seconds:", t.In(tz).Format("2006-01-02T15:04:05 -07:00:00"))
+
// The rest of this function demonstrates the properties of the
// layout string used in the format.
@@ -286,6 +295,8 @@ func ExampleTime_Format() {
// default format: 2015-02-25 11:06:39 -0800 PST
// Unix format: Wed Feb 25 11:06:39 PST 2015
// Same, in UTC: Wed Feb 25 19:06:39 UTC 2015
+ //in Shanghai with seconds: 2015-02-26T03:06:39 +080000
+ //in Shanghai with colon seconds: 2015-02-26T03:06:39 +08:00:00
//
// Formats:
//