More consistent use of layout vs format

This commit is contained in:
Mark McGranaghan 2014-04-15 18:14:23 -07:00
parent 7f996bd048
commit 915697101b
3 changed files with 21 additions and 27 deletions

View File

@ -10,27 +10,24 @@ func main() {
p := fmt.Println
// Here's a basic example of formatting a time
// according to RFC3339, using the corresponding format
// according to RFC3339, using the corresponding layout
// constant.
t := time.Now()
p(t.Format(time.RFC3339))
// Time parsing uses the same format values as `Format`
// does.
// Time parsing uses the same layout values as `Format`.
t1, e := time.Parse(
time.RFC3339,
"2012-11-01T22:08:41+00:00")
p(t1)
// `Format` and `Parse` uses example-based formats. They
// take a formatted version of the reference time
// `Mon Jan 2 15:04:05 MST 2006` to determine the
// general pattern with which to format/parse the given
// time/string. The example time must be exactly as shown:
// the year 2006, 15 for the hour, Monday for the day of
// the week, etc. Usually you'll use a constant from
// `time` for these formats, but you can also supply
// custom formats.
// `Format` and `Parse` uses example-based layouts. Usually
// you'll use a constant from `time` for these layouts, but
// you can also supply custom layouts. Layouts must use the
// reference time `Mon Jan 2 15:04:05 MST 2006` to show the
// pattern with which to format/parse a given time/string.
// The example time must be exactly as shown: the year 2006,
// 15 for the hour, Monday for the day of the week, etc.
p(t.Format("3:04PM"))
p(t.Format("Mon Jan _2 15:04:05 2006"))
p(t.Format("2006-01-02T15:04:05.999999-07:00"))

View File

@ -1,2 +1,2 @@
f036cc1b8d2c2f5c5630c323001fb96efddbc7a8
siwR2J2ke0
52b9bc757a1de989f28665c86ac1f84e17fc0ffc
SGS6wIVnDd

View File

@ -40,7 +40,7 @@ pattern-based layouts.</p>
</td>
<td class="code leading">
<a href="http://play.golang.org/p/siwR2J2ke0"><img title="Run code" src="play.png" class="run" /></a>
<a href="http://play.golang.org/p/SGS6wIVnDd"><img title="Run code" src="play.png" class="run" /></a>
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
</pre></div>
@ -76,7 +76,7 @@ pattern-based layouts.</p>
<tr>
<td class="docs">
<p>Here&rsquo;s a basic example of formatting a time
according to RFC3339, using the corresponding format
according to RFC3339, using the corresponding layout
constant.</p>
</td>
@ -91,8 +91,7 @@ constant.</p>
<tr>
<td class="docs">
<p>Time parsing uses the same format values as <code>Format</code>
does.</p>
<p>Time parsing uses the same layout values as <code>Format</code>.</p>
</td>
<td class="code leading">
@ -108,15 +107,13 @@ does.</p>
<tr>
<td class="docs">
<p><code>Format</code> and <code>Parse</code> uses example-based formats. They
take a formatted version of the reference time
<code>Mon Jan 2 15:04:05 MST 2006</code> to determine the
general pattern with which to format/parse the given
time/string. The example time must be exactly as shown:
the year 2006, 15 for the hour, Monday for the day of
the week, etc. Usually you&rsquo;ll use a constant from
<code>time</code> for these formats, but you can also supply
custom formats.</p>
<p><code>Format</code> and <code>Parse</code> uses example-based layouts. Usually
you&rsquo;ll use a constant from <code>time</code> for these layouts, but
you can also supply custom layouts. Layouts must use the
reference time <code>Mon Jan 2 15:04:05 MST 2006</code> to show the
pattern with which to format/parse a given time/string.
The example time must be exactly as shown: the year 2006,
15 for the hour, Monday for the day of the week, etc.</p>
</td>
<td class="code leading">