Documentation
¶
Index ¶
- Variables
- func Since(t any) time.Duration
- func Until(t any) time.Duration
- type ParseError
- type Time
- func Date(year int, month time.Month, day, hour, min, sec, nsec int, ...) Time
- func New(t ...time.Time) Time
- func Now() Time
- func Parse(layout, value string) (Time, error)
- func ParseInLocation(layout, value string, loc *time.Location) (Time, error)
- func ParseInLocationName(layout, value, name string) (Time, error)
- func Unix(sec, nsec int64) Time
- func UnixMicro(usec int64) Time
- func UnixMilli(msec int64) Time
- func (t Time) Add(d time.Duration) Time
- func (t Time) AddDate(years int, months int, days int) Time
- func (t Time) After(u any) bool
- func (t Time) AppendFormat(b []byte, layout string) []byte
- func (t Time) Before(u any) bool
- func (t Time) Compare(u any) int
- func (t Time) EndOfDay() Time
- func (t Time) EndOfHalfYear() Time
- func (t Time) EndOfHour() Time
- func (t Time) EndOfMinute() Time
- func (t Time) EndOfMonth() Time
- func (t Time) EndOfQuarter() Time
- func (t Time) EndOfSecond() Time
- func (t Time) EndOfYear() Time
- func (t Time) Equal(u any) bool
- func (t Time) Format(layout string) string
- func (t Time) Hour12() int
- func (t Time) In(loc *time.Location) Time
- func (t Time) Local() Time
- func (t Time) Microsecond() int
- func (t Time) Millisecond() int
- func (t Time) Round(d time.Duration) Time
- func (t Time) StartOfDay() Time
- func (t Time) StartOfHalfYear() Time
- func (t Time) StartOfHour() Time
- func (t Time) StartOfMinute() Time
- func (t Time) StartOfMonth() Time
- func (t Time) StartOfQuarter() Time
- func (t Time) StartOfSecond() Time
- func (t Time) StartOfYear() Time
- func (t Time) Sub(u any) time.Duration
- func (t Time) Truncate(d time.Duration) Time
- func (t Time) UTC() Time
- func (t Time) ZoneBounds() (Time, Time)
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotTime error = errors.New("not a Time")
)
Functions ¶
Types ¶
type ParseError ¶
ParseError is the error that happens when parsing the time string by the layout.
func (*ParseError) Error ¶
func (pe *ParseError) Error() string
type Time ¶
func Date ¶
Date creates and returns a new Time by the specific values. The location is an optional parameter, default time.UTC.
func New ¶
New creates and returns a new Time. It'll initialize by the parameter, or set the time to now.
func Parse ¶
Parse parses a formatted string with the layout and returns the time value it represents.
func ParseInLocation ¶
ParseInLocation parses a formatted string with the layout and the given location, and returns the time value it represents.
func ParseInLocationName ¶
ParseInLocationName tries to load the location with the given name, parses a formatted string with the layout and the location, and returns the time value it represents.
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 UnixMicro ¶
UnixMicro returns the local Time corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
func UnixMilli ¶
UnixMilli returns the local Time corresponding to the given Unix time, msec milliseconds since January 1, 1970 UTC.
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.
func (Time) AppendFormat ¶
AppendFormat is like Format but appends the textual representation to b and returns the extended buffer.
func (Time) Compare ¶
Compare compares the time instant t with u. If t is before u, it returns -1; if t is after u, it returns +1; if they're the same, it returns 0.
func (Time) EndOfHalfYear ¶ added in v0.2.0
EndOfHalfYear returns the end time of the half year.
func (Time) EndOfMinute ¶ added in v0.2.0
EndOfMinute returns the end time of the minute.
func (Time) EndOfMonth ¶ added in v0.2.0
EndOfMonth returns the end time of the month.
func (Time) EndOfQuarter ¶ added in v0.2.0
EndOfQuarter returns the end time of the quarter.
func (Time) EndOfSecond ¶ added in v0.2.0
EndOfSecond returns the end time of the second.
func (Time) Equal ¶
Equal reports whether t and u represent the same time instant. Two times can be equal even if they are in different locations. For example, 6:00 +0200 and 4:00 UTC are Equal.
func (Time) Format ¶
Format returns a string of the time formatted by the layout from the parameter.
func (Time) Hour12 ¶
Hour12 returns the 12-hours clock hour offset within the day specified by the time, in the range [1, 12]. See https://en.wikipedia.org/wiki/12-hour_clock for more details about the value.
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) Microsecond ¶
Microsecond returns the microsecond offset within the second specified by the time, in the range [0, 999999].
func (Time) Millisecond ¶
Millisecond returns the millisecond offset within the second specified by the time, in the range [0, 999].
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) StartOfDay ¶ added in v0.2.0
StartOfDay returns the start time of the day.
func (Time) StartOfHalfYear ¶ added in v0.2.0
StartOfHalfYear returns the start time of the half year.
func (Time) StartOfHour ¶ added in v0.2.0
StartOfHour returns the start time of the hour.
func (Time) StartOfMinute ¶ added in v0.2.0
StartOfMinute returns the start time of the minute.
func (Time) StartOfMonth ¶ added in v0.2.0
StartOfMonth returns the start time of the month.
func (Time) StartOfQuarter ¶ added in v0.2.0
StartOfQuarter returns the start time of the quarter.
func (Time) StartOfSecond ¶ added in v0.2.0
StartOfSecond returns the start time of the second.
func (Time) StartOfYear ¶ added in v0.2.0
StartOfYear returns the start time of the year.
func (Time) Sub ¶
Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).
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) ZoneBounds ¶
ZoneBounds returns the bounds of the time zone in effect at time t. The zone begins at start and the next zone begins at end. If the zone begins at the beginning of time, start will be returned as a zero Time. If the zone goes on forever, end will be returned as a zero Time. The Location of the returned times will be the same as t.