aboutsummaryrefslogtreecommitdiff
path: root/src/time
diff options
context:
space:
mode:
authorJean de Klerk <deklerk@google.com>2020-02-24 13:44:56 -0700
committerJean de Klerk <deklerk@google.com>2020-02-25 04:34:15 +0000
commit0d4fa27fd71d12670b7efe06fce3a5b769fa79ce (patch)
treef2f111c99288d54087a663aca98dd4d9bf5e7fc6 /src/time
parent7485050c0f55492c0fdfc41f7564f3da37a1a308 (diff)
downloadgo-0d4fa27fd71d12670b7efe06fce3a5b769fa79ce.tar.gz
go-0d4fa27fd71d12670b7efe06fce3a5b769fa79ce.zip
time: add basic YYYY/MM/DD example to time docs
This is a _very_ common question [1]. Let's just make an example for it. 1: https://www.google.com/search?q=golang+yyyy-mm-dd&oq=golang+yyyy-mm-dd&aqs=chrome..69i57j0l4j69i64l3.6015j0j7&sourceid=chrome&ie=UTF-8 Change-Id: I32ae689b91018d326f31a2442a1beaf68dddf13c Reviewed-on: https://go-review.googlesource.com/c/go/+/220595 Run-TryBot: Jean de Klerk <deklerk@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/time')
-rw-r--r--src/time/example_test.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index 5a037daeaf..fe8e042d69 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -245,14 +245,15 @@ func ExampleTime_Format() {
fmt.Printf("error: for %q got %q; expected %q\n", layout, got, want)
return
}
- fmt.Printf("%-15s %q gives %q\n", name, layout, got)
+ fmt.Printf("%-16s %q gives %q\n", name, layout, got)
}
// Print a header in our output.
fmt.Printf("\nFormats:\n\n")
- // A simple starter example.
- do("Basic", "Mon Jan 2 15:04:05 MST 2006", "Sat Mar 7 11:06:39 PST 2015")
+ // Simple starter examples.
+ do("Basic full date", "Mon Jan 2 15:04:05 MST 2006", "Sat Mar 7 11:06:39 PST 2015")
+ do("Basic short date", "2006/01/02", "2015/03/07")
// 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.
@@ -308,16 +309,17 @@ func ExampleTime_Format() {
//
// Formats:
//
- // Basic "Mon Jan 2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
- // No pad "<2>" gives "<7>"
- // Spaces "<_2>" gives "< 7>"
- // Zeros "<02>" gives "<07>"
- // Suppressed pad "04:05" gives "06:39"
- // Unix "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
- // AM/PM "3PM==3pm==15h" gives "11AM==11am==11h"
- // No fraction "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
- // 0s for fraction "15:04:05.00000" gives "11:06:39.12340"
- // 9s for fraction "15:04:05.99999999" gives "11:06:39.1234"
+ // Basic full date "Mon Jan 2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
+ // Basic short date "2006/01/02" gives "2015/03/07"
+ // No pad "<2>" gives "<7>"
+ // Spaces "<_2>" gives "< 7>"
+ // Zeros "<02>" gives "<07>"
+ // Suppressed pad "04:05" gives "06:39"
+ // Unix "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
+ // AM/PM "3PM==3pm==15h" gives "11AM==11am==11h"
+ // No fraction "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
+ // 0s for fraction "15:04:05.00000" gives "11:06:39.12340"
+ // 9s for fraction "15:04:05.99999999" gives "11:06:39.1234"
}