Commit 1bfffb67 authored by Rob Pike's avatar Rob Pike

time: improve commentary about standard time and formatting/parsing

Fixes #2965.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5652054
parent 7ef97def
...@@ -16,11 +16,13 @@ const ( ...@@ -16,11 +16,13 @@ const (
// These are predefined layouts for use in Time.Format. // These are predefined layouts for use in Time.Format.
// The standard time used in the layouts is: // The standard time used in the layouts is:
// Mon Jan 2 15:04:05 MST 2006 (MST is GMT-0700) // Mon Jan 2 15:04:05 MST 2006
// which is Unix time 1136243045. // which is Unix time 1136243045. Since MST is GMT-0700,
// (Think of it as 01/02 03:04:05PM '06 -0700.) // the standard time can be thought of as
// To define your own format, write down what the standard // 01/02 03:04:05PM '06 -0700
// time would look like formatted your way. // To define your own format, write down what the standard time would look
// like formatted your way; see the values of constants like ANSIC,
// StampMicro or Kitchen for examples.
// //
// Within the format string, an underscore _ represents a space that may be // Within the format string, an underscore _ represents a space that may be
// replaced by a digit if the following number (a day) has two digits; for // replaced by a digit if the following number (a day) has two digits; for
...@@ -359,10 +361,12 @@ func (b *buffer) String() string { ...@@ -359,10 +361,12 @@ func (b *buffer) String() string {
// Format returns a textual representation of the time value formatted // Format returns a textual representation of the time value formatted
// according to layout. The layout defines the format by showing the // according to layout. The layout defines the format by showing the
// representation of a standard time, which is then used to describe // representation of the standard time,
// the time to be formatted. Predefined layouts ANSIC, UnixDate, // Mon Jan 2 15:04:05 -0700 MST 2006
// RFC3339 and others describe standard representations. For more // which is then used to describe the time to be formatted. Predefined
// information about the formats, see the documentation for ANSIC. // layouts ANSIC, UnixDate, RFC3339 and others describe standard
// representations. For more information about the formats and the
// definition of the standard time, see the documentation for ANSIC.
func (t Time) Format(layout string) string { func (t Time) Format(layout string) string {
var ( var (
year int = -1 year int = -1
...@@ -605,13 +609,15 @@ func skip(value, prefix string) (string, error) { ...@@ -605,13 +609,15 @@ func skip(value, prefix string) (string, error) {
} }
// Parse parses a formatted string and returns the time value it represents. // Parse parses a formatted string and returns the time value it represents.
// The layout defines the format by showing the representation of a standard // The layout defines the format by showing the representation of the
// time, which is then used to describe the string to be parsed. Predefined // standard time,
// layouts ANSIC, UnixDate, RFC3339 and others describe standard // Mon Jan 2 15:04:05 -0700 MST 2006
// representations.For more information about the formats, see the // which is then used to describe the string to be parsed. Predefined layouts
// documentation for ANSIC. // ANSIC, UnixDate, RFC3339 and others describe standard representations. For
// more information about the formats and the definition of the standard
// time, see the documentation for ANSIC.
// //
// Elements omitted from the value are assumed to be zero, or when // Elements omitted from the value are assumed to be zero or, when
// zero is impossible, one, so parsing "3:04pm" returns the time // zero is impossible, one, so parsing "3:04pm" returns the time
// corresponding to Jan 1, year 0, 15:04:00 UTC. // corresponding to Jan 1, year 0, 15:04:00 UTC.
// Years must be in the range 0000..9999. The day of the week is checked // Years must be in the range 0000..9999. The day of the week is checked
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment