Documentation ¶
Index ¶
- Constants
- func ParseISO8601Timestamp(s string) (time.Time, error)
- type Time
- func (t Time) Add(d time.Duration) Time
- func (t Time) AddDate(years int, months int, days int) Time
- func (t Time) In(loc *time.Location) Time
- func (t Time) Local() Time
- func (t Time) Round(d time.Duration) Time
- func (t Time) String() string
- func (t Time) Truncate(d time.Duration) Time
- func (t Time) UTC() Time
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t *Time) UnmarshalText(data []byte) error
Constants ¶
const ISO8601CompactFormat = "20060102T150405Z"
ISO8601CompactFormat is a layout for time.Format that prints a time value in the most compact ISO8601 format available. This assumes the time value is in UTC, and returns the time zone as 'Z'.
Variables ¶
This section is empty.
Functions ¶
func ParseISO8601Timestamp ¶
ParseISO8601Timestamp converts an ISO 8601 timestamp into a time.Time result. Compared to time.Parse(time.RFC3339) and time.Parse(time.RFC3339Nano), this accepts the full range of ISO 8601 formats and the RFC 3339 variants.
Types ¶
type Time ¶
Time extends time.Time to handle valid ISO 8601 (but invalid RFC 3336) formatted timestamps in UnmarshalText.
func Date ¶
Date returns the Time corresponding to
yyyy-mm-dd hh:mm:ss + nsec nanoseconds
in the appropriate zone for that time in the given location.
The month, day, hour, min, sec, and nsec values may be outside their usual ranges and will be normalized during the conversion. For example, October 32 converts to November 1.
A daylight savings time transition skips or repeats times. For example, in the United States, March 13, 2011 2:15am never occurred, while November 6, 2011 1:15am occurred twice. In such cases, the choice of time zone, and therefore the time, is not well-defined. Date returns a time that is correct in one of the two zones involved in the transition, but it does not guarantee which.
Date panics if loc is nil.
func Unix ¶
Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).
func (Time) AddDate ¶
AddDate returns the time corresponding to adding the given number of years, months, and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010.
AddDate normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.
func (Time) In ¶
In returns a copy of t representing the same time instant, but with the copy's location information set to loc for display purposes.
In panics if loc is nil.
func (Time) Round ¶
Round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
Round operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Round(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (Time) String ¶
String returns the time formatted using the RFC3339Nano string:
"2006-01-02T15:04:05.999999999Z07:00"
func (Time) Truncate ¶
Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in any ISO 8601 format.
func (*Time) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The time is expected to be in ISO 8601 format.