dtime

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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 Date added in v0.0.8

func Date() string

Date 日期

func Datetime added in v0.0.8

func Datetime() string

Datetime 日期时间

func FuncCost added in v0.0.8

func FuncCost(f func()) int64

FuncCost 执行函数耗时

func ISO8601 added in v0.0.8

func ISO8601() string

ISO8601 格式的时间

func Microsecond added in v0.0.8

func Microsecond() int64

Microsecond 微秒

func Millisecond added in v0.0.8

func Millisecond() int64

Millisecond 获取毫秒

func Nanosecond added in v0.0.8

func Nanosecond() int64

Nanosecond 纳秒

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

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 RFC822 added in v0.0.8

func RFC822() string

RFC822 格式的时间

func Second added in v0.0.8

func Second() int64

Second 获取时间戳秒

func SetTimeZone

func SetTimeZone(zone string) error

SetTimeZone 设置时区

func Timestamp

func Timestamp() int64

Timestamp 当前时间戳

func TimestampMicro added in v0.0.8

func TimestampMicro() int64

TimestampMicro 获取微秒时间戳

func TimestampMicroStr added in v0.0.8

func TimestampMicroStr() string

TimestampMicroStr 获取微秒时间戳的字符串格式

func TimestampMilli added in v0.0.8

func TimestampMilli() int64

TimestampMilli 获取毫秒时间戳

func TimestampMilliStr added in v0.0.8

func TimestampMilliStr() string

TimestampMilliStr 获取毫秒时间戳的字符串格式

func TimestampNano added in v0.0.8

func TimestampNano() int64

TimestampNano 获取纳秒时间戳

func TimestampNanoStr added in v0.0.8

func TimestampNanoStr() string

TimestampNanoStr 获取纳秒时间戳的字符格式

func TimestampStr added in v0.0.8

func TimestampStr() string

TimestampStr 获取时间戳的字符串形式

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

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

ConvertZone 从字符串时间转换为0时区时间

func New

func New(param ...interface{}) *Time

New 通过参数创建时间对象

func NewFromStr

func NewFromStr(str string) *Time

NewFromStr 通过字符串创建一个dtime.time对象

func NewFromStrFormat

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 added in v0.0.8

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

func NewFromTime(t time.Time) *Time

NewFromTime 通过time.time对象创建一个dtime对象

func NewFromTimeStamp

func NewFromTimeStamp(timestamp int64) *Time

NewFromTimeStamp 通过时间戳创建dtime.Time对象

func Now

func Now() *Time

Now 返回一个time对象,时间设置为当前时间

func ParseTimeFromContent added in v0.0.8

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

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

StrToTime 通过字符串转换成dtime.Time对象

func StrToTimeFormat

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

StrToTimeFormat 传入时间字符串,要转换的格式,生成dtime.Time对象

func StrToTimeLayout

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

StrToTimeLayout 把str时间转换成layout布局的时间格式

func (*Time) Add added in v0.0.8

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

Add 增加制定的时间

func (*Time) AddDate added in v0.0.8

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

AddDate adds year, month and day to the time.

func (*Time) AddStr added in v0.0.8

func (that *Time) AddStr(duration string) (*Time, error)

AddStr 通过字符串格式的时间增加时间

func (*Time) After added in v0.0.8

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

After reports whether the time instant t is after u.

func (*Time) Before added in v0.0.8

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

Before reports whether the time instant t is before u.

func (*Time) Clone added in v0.0.8

func (that *Time) Clone() *Time

Clone 返回一个新的时间对象,值为当前时间

func (*Time) DayOfYear

func (that *Time) DayOfYear() int

DayOfYear 当天是当年的第几天

func (*Time) DaysInMonth

func (that *Time) DaysInMonth() int

DaysInMonth 返回当前月份的天数

func (*Time) EndOfDay added in v0.0.8

func (that *Time) EndOfDay() *Time

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

func (that *Time) EndOfHalf() *Time

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

func (that *Time) EndOfHour() *Time

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

func (that *Time) EndOfMinute() *Time

EndOfMinute clones and returns a new time of which the seconds is set to 59.

func (*Time) EndOfMonth added in v0.0.8

func (that *Time) EndOfMonth() *Time

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

func (that *Time) EndOfQuarter() *Time

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

func (that *Time) EndOfWeek() *Time

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

func (that *Time) EndOfYear() *Time

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

func (that *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

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

Format 格式换Time格式

func (*Time) FormatNew

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

FormatNew 转换成指定格式,并返回一个新的对象

func (*Time) FormatTo

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

FormatTo 要转换成的格式

func (*Time) ISO8601 added in v0.0.8

func (that *Time) ISO8601() string

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

func (*Time) IsLeapYear

func (that *Time) IsLeapYear() bool

IsLeapYear 当年是否是闰年

func (*Time) IsZero added in v0.0.8

func (that *Time) IsZero() bool

IsZero 判断时间是否为0时间

func (*Time) Layout

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

Layout 设置时间个格式化

func (*Time) LayoutNew

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

LayoutNew 使用layout格式格式化时间并返回一个新的对象

func (*Time) LayoutTo

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

LayoutTo 格式化格式

func (*Time) Local added in v0.0.8

func (that *Time) Local() *Time

Local 将时间转换成当前时区

func (*Time) MarshalJSON added in v0.0.8

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Time) Microsecond

func (that *Time) Microsecond() int

Microsecond 返回微秒长度

func (*Time) Millisecond

func (that *Time) Millisecond() int

Millisecond 返回毫秒长度

func (*Time) Month added in v0.0.8

func (that *Time) Month() int

Month 月份

func (*Time) Nanosecond

func (that *Time) Nanosecond() int

Nanosecond 返回纳秒长度

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) RFC822 added in v0.0.8

func (that *Time) RFC822() string

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

func (*Time) Round added in v0.0.8

func (that *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) Scan added in v0.0.8

func (that *Time) Scan(value interface{}) error

Scan 从 database/sql包中扫描时间格式的数据到golang格式

func (*Time) Second added in v0.0.8

func (that *Time) Second() int

Second 秒长度

func (*Time) StartOfDay added in v0.0.8

func (that *Time) StartOfDay() *Time

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

func (that *Time) StartOfHalf() *Time

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

func (that *Time) StartOfHour() *Time

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

func (that *Time) StartOfMinute() *Time

StartOfMinute clones and returns a new time of which the seconds is set to 0.

func (*Time) StartOfMonth added in v0.0.8

func (that *Time) StartOfMonth() *Time

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

func (that *Time) StartOfQuarter() *Time

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

func (that *Time) StartOfWeek() *Time

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

func (that *Time) StartOfYear() *Time

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) String

func (that *Time) String() string

返回时间的字符串格式

func (*Time) Sub added in v0.0.8

func (that *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

func (that *Time) Timestamp() int64

Timestamp 当前时间戳

func (*Time) TimestampMicro added in v0.0.8

func (that *Time) TimestampMicro() int64

TimestampMicro 获取毫秒时间戳

func (*Time) TimestampMicroStr added in v0.0.8

func (that *Time) TimestampMicroStr() string

TimestampMicroStr 获取毫秒时间戳的字符串表示

func (*Time) TimestampMilli added in v0.0.8

func (that *Time) TimestampMilli() int64

TimestampMilli 获取微秒时间戳

func (*Time) TimestampMilliStr added in v0.0.8

func (that *Time) TimestampMilliStr() string

TimestampMilliStr 获取微妙时间戳的字符串表示

func (*Time) TimestampNano added in v0.0.8

func (that *Time) TimestampNano() int64

TimestampNano 获取纳秒时间戳

func (*Time) TimestampNanoStr added in v0.0.8

func (that *Time) TimestampNanoStr() string

TimestampNanoStr 获取纳秒时间戳的字符串表示

func (*Time) TimestampStr added in v0.0.8

func (that *Time) TimestampStr() string

TimestampStr 获取时间戳的字符串表示

func (*Time) ToLocation added in v0.0.8

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

ToLocation 把当前时间转换成指定时区的时间

func (*Time) ToZone added in v0.0.8

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

ToZone 把当前时间转换成指定时区的时间,如: Asia/Shanghai

func (*Time) Truncate added in v0.0.8

func (that *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 added in v0.0.8

func (that *Time) UTC() *Time

UTC 返回utc时间

func (*Time) UnmarshalJSON added in v0.0.8

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*Time) UnmarshalText added in v0.0.8

func (that *Time) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. Note that it overwrites the same implementer of `time.Time`.

func (*Time) Value added in v0.0.8

func (that *Time) Value() (driver.Value, error)

Value 把当前时间格式转换成database/sql/driver可以识别的数据格式

func (*Time) WeeksOfYear

func (that *Time) WeeksOfYear() int

WeeksOfYear 返回当前处于当年的第几周

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL