Documentation
¶
Overview ¶
时间管理
Index ¶
- Constants
- func Date() string
- func Datetime() string
- func FuncCost(f func()) int64
- func Microsecond() int64
- func Millisecond() int64
- func Nanosecond() int64
- func Second() int64
- func SetInterval(t time.Duration, callback func() bool)
- func SetTimeZone(zone string) error
- func SetTimeout(t time.Duration, callback func())
- type Time
- func ConvertZone(strTime string, toZone string, fromZone ...string) (*Time, error)
- func New(t ...time.Time) *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 (t *Time) Add(d time.Duration) *Time
- func (t *Time) AddDate(years int, months int, days int) *Time
- func (t *Time) Clone() *Time
- func (t *Time) Format(format string) string
- func (t *Time) Layout(layout string) string
- func (t *Time) Local() *Time
- func (t *Time) Microsecond() int64
- func (t *Time) Millisecond() int64
- func (t *Time) Nanosecond() int64
- func (t *Time) Round(d time.Duration) *Time
- func (t *Time) Second() int64
- func (t *Time) String() string
- func (t *Time) ToLocation(location *time.Location) *Time
- func (t *Time) ToTime() time.Time
- func (t *Time) ToZone(zone string) *Time
- func (t *Time) Truncate(d time.Duration) *Time
- func (t *Time) UTC() *Time
Constants ¶
View Source
const ( // 常用时间格式正则匹配,支持的标准时间格式: // "2017-12-14 04:51:34 +0805 LMT", // "2017-12-14 04:51:34 +0805 LMT", // "2006-01-02T15:04:05Z07:00", // "2014-01-17T01:19:15+08:00", // "2018-02-09T20:46:17.897Z", // "2018-02-09 20:46:17.897", // "2018-02-09T20:46:17Z", // "2018-02-09 20:46:17", // "2018/10/31 - 16:38:46" // "2018-02-09", // 日期连接符号支持'-'或者'/' TIME_REAGEX_PATTERN1 = `(\d{2,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]*)` // 01-Nov-2018 11:50:28 // 01/Nov/2018 11:50:28 // 01/Nov/2018:11:50:28 // 01/Nov/18 11:50:28 // 01/Nov/18 11:50:28 TIME_REAGEX_PATTERN2 = `` /* 132-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func SetInterval ¶
类似与js中的SetInterval,每隔一段时间后执行回调函数,当回调函数返回true,那么继续执行,否则终止执行,该方法是异步的 注意:由于采用的是循环而不是递归操作,因此间隔时间将会以上一次回调函数执行完成的时间来计算
Types ¶
type Time ¶
func ConvertZone ¶
时区转换
func NewFromStrFormat ¶
从字符串转换为时间对象,指定字符串时间格式,format格式形如:Y-m-d H:i:s
func NewFromStrLayout ¶
从字符串转换为时间对象,通过标准库layout格式进行解析,layout格式形如:2006-01-02 15:04:05
func ParseTimeFromContent ¶ added in v1.1.994
从字符串内容中(也可以是文件名称等等)解析时间,并返回解析成功的时间对象,否则返回nil。 注意当内容中存在多个时间时,会解析第一个。 format参数可以指定需要解析的时间格式。
func StrToTimeFormat ¶
字符串转换为时间对象,指定字符串时间格式,format格式形如:Y-m-d H:i:s
func StrToTimeLayout ¶
字符串转换为时间对象,通过标准库layout格式进行解析,layout格式形如:2006-01-02 15:04:05
func (*Time) Round ¶
Round将舍入t的结果返回到d的最接近的倍数(从零时间开始)。 中间值的舍入行为是向上舍入。 如果d <= 0,Round返回t剥离任何单调时钟读数但不改变。 Round作为零时间以来的绝对持续时间运行; 它不适用于当时的演示形式。 因此,Round(Hour)可能会返回非零分钟的时间,具体取决于时间的位置。
func (*Time) ToLocation ¶
时区转换为指定的时区(通过time.Location)
Click to show internal directories.
Click to hide internal directories.