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

View File

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

View File

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