Skip to content

Commit 0d4fa27

Browse files
committed
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>
1 parent 7485050 commit 0d4fa27

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/time/example_test.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,15 @@ func ExampleTime_Format() {
245245
fmt.Printf("error: for %q got %q; expected %q\n", layout, got, want)
246246
return
247247
}
248-
fmt.Printf("%-15s %q gives %q\n", name, layout, got)
248+
fmt.Printf("%-16s %q gives %q\n", name, layout, got)
249249
}
250250

251251
// Print a header in our output.
252252
fmt.Printf("\nFormats:\n\n")
253253

254-
// A simple starter example.
255-
do("Basic", "Mon Jan 2 15:04:05 MST 2006", "Sat Mar 7 11:06:39 PST 2015")
254+
// Simple starter examples.
255+
do("Basic full date", "Mon Jan 2 15:04:05 MST 2006", "Sat Mar 7 11:06:39 PST 2015")
256+
do("Basic short date", "2006/01/02", "2015/03/07")
256257

257258
// For fixed-width printing of values, such as the date, that may be one or
258259
// two characters (7 vs. 07), use an _ instead of a space in the layout string.
@@ -308,16 +309,17 @@ func ExampleTime_Format() {
308309
//
309310
// Formats:
310311
//
311-
// Basic "Mon Jan 2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
312-
// No pad "<2>" gives "<7>"
313-
// Spaces "<_2>" gives "< 7>"
314-
// Zeros "<02>" gives "<07>"
315-
// Suppressed pad "04:05" gives "06:39"
316-
// Unix "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
317-
// AM/PM "3PM==3pm==15h" gives "11AM==11am==11h"
318-
// No fraction "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
319-
// 0s for fraction "15:04:05.00000" gives "11:06:39.12340"
320-
// 9s for fraction "15:04:05.99999999" gives "11:06:39.1234"
312+
// Basic full date "Mon Jan 2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
313+
// Basic short date "2006/01/02" gives "2015/03/07"
314+
// No pad "<2>" gives "<7>"
315+
// Spaces "<_2>" gives "< 7>"
316+
// Zeros "<02>" gives "<07>"
317+
// Suppressed pad "04:05" gives "06:39"
318+
// Unix "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
319+
// AM/PM "3PM==3pm==15h" gives "11AM==11am==11h"
320+
// No fraction "Mon Jan _2 15:04:05 MST 2006" gives "Sat Mar 7 11:06:39 PST 2015"
321+
// 0s for fraction "15:04:05.00000" gives "11:06:39.12340"
322+
// 9s for fraction "15:04:05.99999999" gives "11:06:39.1234"
321323

322324
}
323325

0 commit comments

Comments
 (0)