Documentation ¶
Index ¶
- Constants
- func Date() string
- func Datetime() string
- func FuncCost(f func()) int64
- func ISO8601() string
- func Microsecond() int64
- func Millisecond() int64
- func Nanosecond() int64
- func ParseDuration(s string) (time.Duration, error)
- func RFC822() string
- func Second() int64
- func SetTimeZone(zone string) error
- func Timestamp() int64
- func TimestampMicro() int64
- func TimestampMicroStr() string
- func TimestampMilli() int64
- func TimestampMilliStr() string
- func TimestampNano() int64
- func TimestampNanoStr() string
- func TimestampStr() string
- type Time
- func ConvertZone(strTime string, toZone string, fromZone ...string) (*Time, error)
- func New(param ...interface{}) *Time
- func NewFromStr(str string) *Time
- func NewFromStrFormat(str string, format string) *Time
- func NewFromStrLayout(str string, layout string) *Time
- func NewFromTime(t time.Time) *Time
- func NewFromTimeStamp(timestamp int64) *Time
- func Now() *Time
- func ParseTimeFromContent(content string, format ...string) *Time
- func StrToTime(str string, format ...string) (*Time, error)
- func StrToTimeFormat(str string, format string) (*Time, error)
- func StrToTimeLayout(str string, layout string) (*Time, error)
- func (that *Time) Add(d time.Duration) *Time
- func (that *Time) AddDate(years int, months int, days int) *Time
- func (that *Time) AddStr(duration string) (*Time, error)
- func (that *Time) After(u *Time) bool
- func (that *Time) Before(u *Time) bool
- func (that *Time) Clone() *Time
- func (that *Time) DayOfYear() int
- func (that *Time) DaysInMonth() int
- func (that *Time) EndOfDay() *Time
- func (that *Time) EndOfHalf() *Time
- func (that *Time) EndOfHour() *Time
- func (that *Time) EndOfMinute() *Time
- func (that *Time) EndOfMonth() *Time
- func (that *Time) EndOfQuarter() *Time
- func (that *Time) EndOfWeek() *Time
- func (that *Time) EndOfYear() *Time
- func (that *Time) Equal(u *Time) bool
- func (that *Time) Format(format string) string
- func (that *Time) FormatNew(format string) *Time
- func (that *Time) FormatTo(format string) *Time
- func (that *Time) ISO8601() string
- func (that *Time) IsLeapYear() bool
- func (that *Time) IsZero() bool
- func (that *Time) Layout(layout string) string
- func (that *Time) LayoutNew(layout string) *Time
- func (that *Time) LayoutTo(layout string) *Time
- func (that *Time) Local() *Time
- func (that *Time) MarshalJSON() ([]byte, error)
- func (that *Time) Microsecond() int
- func (that *Time) Millisecond() int
- func (that *Time) Month() int
- func (that *Time) Nanosecond() int
- func (that *Time) NoValidation()
- func (that *Time) RFC822() string
- func (that *Time) Round(d time.Duration) *Time
- func (that *Time) Scan(value interface{}) error
- func (that *Time) Second() int
- func (that *Time) StartOfDay() *Time
- func (that *Time) StartOfHalf() *Time
- func (that *Time) StartOfHour() *Time
- func (that *Time) StartOfMinute() *Time
- func (that *Time) StartOfMonth() *Time
- func (that *Time) StartOfQuarter() *Time
- func (that *Time) StartOfWeek() *Time
- func (that *Time) StartOfYear() *Time
- func (that *Time) String() string
- func (that *Time) Sub(u *Time) time.Duration
- func (that *Time) Timestamp() int64
- func (that *Time) TimestampMicro() int64
- func (that *Time) TimestampMicroStr() string
- func (that *Time) TimestampMilli() int64
- func (that *Time) TimestampMilliStr() string
- func (that *Time) TimestampNano() int64
- func (that *Time) TimestampNanoStr() string
- func (that *Time) TimestampStr() string
- func (that *Time) ToLocation(location *time.Location) *Time
- func (that *Time) ToZone(zone string) (*Time, error)
- func (that *Time) Truncate(d time.Duration) *Time
- func (that *Time) UTC() *Time
- func (that *Time) UnmarshalJSON(b []byte) error
- func (that *Time) UnmarshalText(data []byte) error
- func (that *Time) Value() (driver.Value, error)
- func (that *Time) WeeksOfYear() int
Constants ¶
const ( D = 24 * time.Hour H = time.Hour M = time.Minute S = time.Second MS = time.Millisecond US = time.Microsecond NS = time.Nanosecond )
一般时间使用的短写
Variables ¶
This section is empty.
Functions ¶
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h", "1d" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".
Very note that it supports unit "d" more than function time.ParseDuration.
func TimestampMicroStr ¶ added in v0.0.8
func TimestampMicroStr() string
TimestampMicroStr 获取微秒时间戳的字符串格式
func TimestampMilliStr ¶ added in v0.0.8
func TimestampMilliStr() string
TimestampMilliStr 获取毫秒时间戳的字符串格式
func TimestampNanoStr ¶ added in v0.0.8
func TimestampNanoStr() string
TimestampNanoStr 获取纳秒时间戳的字符格式
Types ¶
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time is a wrapper for time.Time for additional features.
func ConvertZone ¶ added in v0.0.8
ConvertZone 从字符串时间转换为0时区时间
func NewFromStrFormat ¶
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 ¶ added in v0.0.8
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 NewFromTimeStamp ¶
NewFromTimeStamp 通过时间戳创建dtime.Time对象
func ParseTimeFromContent ¶ added in v0.0.8
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 StrToTimeFormat ¶
StrToTimeFormat 传入时间字符串,要转换的格式,生成dtime.Time对象
func StrToTimeLayout ¶
StrToTimeLayout 把str时间转换成layout布局的时间格式
func (*Time) EndOfDay ¶ added in v0.0.8
EndOfDay clones and returns a new time which is the end of day the and its time is set to 23:59:59.
func (*Time) EndOfHalf ¶ added in v0.0.8
EndOfHalf clones and returns a new time which is the end of the half year and its time is set to 23:59:59.
func (*Time) EndOfHour ¶ added in v0.0.8
EndOfHour clones and returns a new time of which the minutes and seconds are both set to 59.
func (*Time) EndOfMinute ¶ added in v0.0.8
EndOfMinute clones and returns a new time of which the seconds is set to 59.
func (*Time) EndOfMonth ¶ added in v0.0.8
EndOfMonth clones and returns a new time which is the end of the month and its time is set to 23:59:59.
func (*Time) EndOfQuarter ¶ added in v0.0.8
EndOfQuarter clones and returns a new time which is end of the quarter and its time is set to 23:59:59.
func (*Time) EndOfWeek ¶ added in v0.0.8
EndOfWeek clones and returns a new time which is the end of week and its time is set to 23:59:59.
func (*Time) EndOfYear ¶ added in v0.0.8
EndOfYear clones and returns a new time which is the end of the year and its time is set to 23:59:59.
func (*Time) Equal ¶ added in v0.0.8
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) ISO8601 ¶ added in v0.0.8
ISO8601 formats the time as ISO8601 and returns it as string.
func (*Time) MarshalJSON ¶ added in v0.0.8
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Time) NoValidation ¶ added in v0.0.8
func (that *Time) NoValidation()
NoValidation marks this struct object will not be validated by package gvalid.
func (*Time) Round ¶ added in v0.0.8
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.0.8
StartOfDay clones and returns a new time which is the start of day, its time is set to 00:00:00. clone 一个新的时间,并返回这一天的开始时间
func (*Time) StartOfHalf ¶ added in v0.0.8
StartOfHalf clones and returns a new time which is the first day of the half year and its time is set to 00:00:00.
func (*Time) StartOfHour ¶ added in v0.0.8
StartOfHour clones and returns a new time of which the hour, minutes and seconds are set to 0.
func (*Time) StartOfMinute ¶ added in v0.0.8
StartOfMinute clones and returns a new time of which the seconds is set to 0.
func (*Time) StartOfMonth ¶ added in v0.0.8
StartOfMonth clones and returns a new time which is the first day of the month and its is set to 00:00:00
func (*Time) StartOfQuarter ¶ added in v0.0.8
StartOfQuarter clones and returns a new time which is the first day of the quarter and its time is set to 00:00:00.
func (*Time) StartOfWeek ¶ added in v0.0.8
StartOfWeek clones and returns a new time which is the first day of week and its time is set to 00:00:00.
func (*Time) StartOfYear ¶ added in v0.0.8
StartOfYear clones and returns a new time which is the first day of the year and its time is set to 00:00:00.
func (*Time) Sub ¶ added in v0.0.8
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) TimestampMicro ¶ added in v0.0.8
TimestampMicro 获取毫秒时间戳
func (*Time) TimestampMicroStr ¶ added in v0.0.8
TimestampMicroStr 获取毫秒时间戳的字符串表示
func (*Time) TimestampMilli ¶ added in v0.0.8
TimestampMilli 获取微秒时间戳
func (*Time) TimestampMilliStr ¶ added in v0.0.8
TimestampMilliStr 获取微妙时间戳的字符串表示
func (*Time) TimestampNano ¶ added in v0.0.8
TimestampNano 获取纳秒时间戳
func (*Time) TimestampNanoStr ¶ added in v0.0.8
TimestampNanoStr 获取纳秒时间戳的字符串表示
func (*Time) TimestampStr ¶ added in v0.0.8
TimestampStr 获取时间戳的字符串表示
func (*Time) ToLocation ¶ added in v0.0.8
ToLocation 把当前时间转换成指定时区的时间
func (*Time) Truncate ¶ added in v0.0.8
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 ¶ added in v0.0.8
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*Time) UnmarshalText ¶ added in v0.0.8
UnmarshalText implements the encoding.TextUnmarshaler interface. Note that it overwrites the same implementer of `time.Time`.