gf: github.com/gogf/gf/os/gtime Index | Files

package gtime

import "github.com/gogf/gf/os/gtime"

Package gtime provides functionality for measuring and displaying time.

This package should keep much less dependencies with other packages.

Index

Package Files

gtime.go gtime_format.go gtime_time.go gtime_time_wrapper.go

Constants

const (
    D   = 24 * time.Hour
    H   = time.Hour
    M   = time.Minute
    S   = time.Second
    MS  = time.Millisecond
    US  = time.Microsecond
    NS  = time.Nanosecond

    TIME_REAGEX_PATTERN1 = `(\d{4}[-/\.]\d{2}[-/\.]\d{2})[:\sT-]*(\d{0,2}:{0,1}\d{0,2}:{0,1}\d{0,2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)`

    TIME_REAGEX_PATTERN2 = "" /* 136 byte string literal not displayed */
)

func Date Uses

func Date() string

Date returns current date in string like "2006-01-02".

func Datetime Uses

func Datetime() string

Datetime returns current datetime in string like "2006-01-02 15:04:05".

func FuncCost Uses

func FuncCost(f func()) int64

FuncCost calculates the cost time of function <f> in nanoseconds.

func ISO8601 Uses

func ISO8601() string

ISO8601 returns current datetime in ISO8601 format like "2006-01-02T15:04:05-07:00".

func Microsecond Uses

func Microsecond() int64

Microsecond returns the timestamp in microseconds. Deprecated, use TimestampMicro instead.

func Millisecond Uses

func Millisecond() int64

Millisecond returns the timestamp in milliseconds. Deprecated, use TimestampMilli instead.

func Nanosecond Uses

func Nanosecond() int64

Nanosecond returns the timestamp in nanoseconds. Deprecated, use TimestampNano instead.

func RFC822 Uses

func RFC822() string

ISO8601 returns current datetime in RFC822 format like "Mon, 02 Jan 06 15:04 MST".

func Second Uses

func Second() int64

Second returns the timestamp in seconds. Deprecated, use Timestamp instead.

func SetTimeZone Uses

func SetTimeZone(zone string) error

SetTimeZone sets the time zone for current whole process. The parameter <zone> is an area string specifying corresponding time zone, eg: Asia/Shanghai.

Note that the time zone database needed by LoadLocation may not be present on all systems, especially non-Unix systems. LoadLocation looks in the directory or uncompressed zip file named by the ZONEINFO environment variable, if any, then looks in known installation locations on Unix systems, and finally looks in $GOROOT/lib/time/zoneinfo.zip.

func Timestamp Uses

func Timestamp() int64

Timestamp retrieves and returns the timestamp in seconds.

func TimestampMicro Uses

func TimestampMicro() int64

TimestampMicro retrieves and returns the timestamp in microseconds.

func TimestampMicroStr Uses

func TimestampMicroStr() string

TimestampMicroStr is a convenience method which retrieves and returns the timestamp in microseconds as string.

func TimestampMilli Uses

func TimestampMilli() int64

TimestampMilli retrieves and returns the timestamp in milliseconds.

func TimestampMilliStr Uses

func TimestampMilliStr() string

TimestampMilliStr is a convenience method which retrieves and returns the timestamp in milliseconds as string.

func TimestampNano Uses

func TimestampNano() int64

TimestampNano retrieves and returns the timestamp in nanoseconds.

func TimestampNanoStr Uses

func TimestampNanoStr() string

TimestampNanoStr is a convenience method which retrieves and returns the timestamp in nanoseconds as string.

func TimestampStr Uses

func TimestampStr() string

TimestampStr is a convenience method which retrieves and returns the timestamp in seconds as string.

type Time Uses

type Time struct {
    TimeWrapper
}

Time is a wrapper for time.Time for additional features.

func ConvertZone Uses

func ConvertZone(strTime string, toZone string, fromZone ...string) (*Time, error)

ConvertZone converts time in string <strTime> from <fromZone> to <toZone>. The parameter <fromZone> is unnecessary, it is current time zone in default.

func New Uses

func New(t ...time.Time) *Time

New creates and returns a Time object with given time.Time object. The parameter <t> is optional.

func NewFromStr Uses

func NewFromStr(str string) *Time

NewFromStr creates and returns a Time object with given string. Note that it returns nil if there's error occurs.

func NewFromStrFormat Uses

func NewFromStrFormat(str string, format string) *Time

NewFromStrFormat creates and returns a Time object with given string and custom format like: Y-m-d H:i:s. Note that it returns nil if there's error occurs.

func NewFromStrLayout Uses

func NewFromStrLayout(str string, layout string) *Time

NewFromStrLayout creates and returns a Time object with given string and stdlib layout like: 2006-01-02 15:04:05. Note that it returns nil if there's error occurs.

func NewFromTime Uses

func NewFromTime(t time.Time) *Time

NewFromTime creates and returns a Time object with given time.Time object.

func NewFromTimeStamp Uses

func NewFromTimeStamp(timestamp int64) *Time

NewFromTimeStamp creates and returns a Time object with given timestamp, which can be in seconds to nanoseconds.

func Now Uses

func Now() *Time

Now creates and returns a time object of now.

func ParseTimeFromContent Uses

func ParseTimeFromContent(content string, format ...string) *Time

ParseTimeFromContent retrieves time information for content string, it then parses and returns it as *Time object. It returns the first time information if there're more than one time string in the content. It only retrieves and parses the time information with given <format> if it's passed.

func StrToTime Uses

func StrToTime(str string, format ...string) (*Time, error)

StrToTime converts string to *Time object. The parameter <format> is unnecessary, which specifies the format for converting like "Y-m-d H:i:s". If <format> is given, it acts as same as function StrToTimeFormat. If <format> is not given, it converts string as a "standard" datetime string. Note that, it fails and returns error if there's no date string in <str>.

func StrToTimeFormat Uses

func StrToTimeFormat(str string, format string) (*Time, error)

StrToTimeFormat parses string <str> to *Time object with given format <format>. The parameter <format> is like "Y-m-d H:i:s".

func StrToTimeLayout Uses

func StrToTimeLayout(str string, layout string) (*Time, error)

StrToTimeLayout parses string <str> to *Time object with given format <layout>. The parameter <layout> is in stdlib format like "2006-01-02 15:04:05".

func (*Time) Add Uses

func (t *Time) Add(d time.Duration) *Time

Add adds the duration to current time.

func (*Time) AddDate Uses

func (t *Time) AddDate(years int, months int, days int) *Time

AddDate adds year, month and day to the time.

func (*Time) AddStr Uses

func (t *Time) AddStr(duration string) error

AddStr parses the given duration as string and adds it to current time.

func (*Time) After Uses

func (t *Time) After(u *Time) bool

After reports whether the time instant t is after u.

func (*Time) Before Uses

func (t *Time) Before(u *Time) bool

Before reports whether the time instant t is before u.

func (*Time) Clone Uses

func (t *Time) Clone() *Time

Clone returns a new Time object which is a clone of current time object.

func (*Time) DayOfYear Uses

func (t *Time) DayOfYear() int

DayOfYear checks and returns the position of the day for the year.

func (*Time) DaysInMonth Uses

func (t *Time) DaysInMonth() int

DaysInMonth returns the day count of current month.

func (*Time) Equal Uses

func (t *Time) Equal(u *Time) bool

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 CEST and 4:00 UTC are Equal. See the documentation on the Time type for the pitfalls of using == with Time values; most code should use Equal instead.

func (*Time) Format Uses

func (t *Time) Format(format string) string

Format formats and returns the formatted result with custom <format>.

func (*Time) FormatNew Uses

func (t *Time) FormatNew(format string) *Time

FormatNew formats and returns a new Time object with given custom <format>.

func (*Time) FormatTo Uses

func (t *Time) FormatTo(format string) *Time

FormatTo formats <t> with given custom <format>.

func (*Time) ISO8601 Uses

func (t *Time) ISO8601() string

ISO8601 formats the time as ISO8601 and returns it as string.

func (*Time) IsLeapYear Uses

func (t *Time) IsLeapYear() bool

IsLeapYear checks whether the time is leap year.

func (*Time) Layout Uses

func (t *Time) Layout(layout string) string

Layout formats the time with stdlib layout and returns the formatted result.

func (*Time) LayoutNew Uses

func (t *Time) LayoutNew(layout string) *Time

LayoutNew formats the time with stdlib layout and returns the new Time object.

func (*Time) LayoutTo Uses

func (t *Time) LayoutTo(layout string) *Time

LayoutTo formats <t> with stdlib layout.

func (*Time) Local Uses

func (t *Time) Local() *Time

Local converts the time to local timezone.

func (*Time) MarshalJSON Uses

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Time) Microsecond Uses

func (t *Time) Microsecond() int

Microsecond returns the microsecond offset within the second specified by t, in the range [0, 999999].

func (*Time) Millisecond Uses

func (t *Time) Millisecond() int

Millisecond returns the millisecond offset within the second specified by t, in the range [0, 999].

func (*Time) Nanosecond Uses

func (t *Time) Nanosecond() int

Nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].

func (*Time) RFC822 Uses

func (t *Time) RFC822() string

RFC822 formats the time as RFC822 and returns it as string.

func (*Time) Round Uses

func (t *Time) Round(d time.Duration) *Time

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) Second Uses

func (t *Time) Second() int

Second returns the second offset within the minute specified by t, in the range [0, 59].

func (*Time) String Uses

func (t *Time) String() string

String returns current time object as string.

func (*Time) Sub Uses

func (t *Time) Sub(u *Time) time.Duration

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) Timestamp Uses

func (t *Time) Timestamp() int64

Timestamp returns the timestamp in seconds.

func (*Time) TimestampMicro Uses

func (t *Time) TimestampMicro() int64

TimestampMicro returns the timestamp in microseconds.

func (*Time) TimestampMicroStr Uses

func (t *Time) TimestampMicroStr() string

TimestampMicroStr is a convenience method which retrieves and returns the timestamp in microseconds as string.

func (*Time) TimestampMilli Uses

func (t *Time) TimestampMilli() int64

TimestampMilli returns the timestamp in milliseconds.

func (*Time) TimestampMilliStr Uses

func (t *Time) TimestampMilliStr() string

TimestampMilliStr is a convenience method which retrieves and returns the timestamp in milliseconds as string.

func (*Time) TimestampNano Uses

func (t *Time) TimestampNano() int64

TimestampNano returns the timestamp in nanoseconds.

func (*Time) TimestampNanoStr Uses

func (t *Time) TimestampNanoStr() string

TimestampNanoStr is a convenience method which retrieves and returns the timestamp in nanoseconds as string.

func (*Time) TimestampStr Uses

func (t *Time) TimestampStr() string

TimestampStr is a convenience method which retrieves and returns the timestamp in seconds as string.

func (*Time) ToLocation Uses

func (t *Time) ToLocation(location *time.Location) *Time

ToLocation converts current time to specified location.

func (*Time) ToZone Uses

func (t *Time) ToZone(zone string) (*Time, error)

ToZone converts current time to specified zone like: Asia/Shanghai.

func (*Time) Truncate Uses

func (t *Time) Truncate(d time.Duration) *Time

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) UTC Uses

func (t *Time) UTC() *Time

UTC converts current time to UTC timezone.

func (*Time) UnmarshalJSON Uses

func (t *Time) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*Time) WeeksOfYear Uses

func (t *Time) WeeksOfYear() int

WeeksOfYear returns the point of current week for the year.

type TimeWrapper Uses

type TimeWrapper struct {
    time.Time
}

TimeWrapper is a wrapper for stdlib struct time.Time. It's used for overwriting some functions of time.Time, for example: String.

func (TimeWrapper) String Uses

func (t TimeWrapper) String() string

String overwrites the String function of time.Time.

Package gtime imports 8 packages (graph) and is imported by 19 packages. Updated 2020-06-23. Refresh now. Tools for package owners.