Documentation ¶
Index ¶
- Constants
- func GetCurrentDayOfMonth(t time.Time) (day int)
- func GetCurrentDayOfYear(t time.Time) (day int, err error)
- func GetTimeStamp(length int) string
- func OnTimer(kind, duration int, callback func() error) chan error
- type Ztime
- func (this *Ztime) AddHour(n int) *Ztime
- func (this *Ztime) AddMinute(n int) *Ztime
- func (this *Ztime) Format(format string) (string, error)
- func (this *Ztime) Now() *Ztime
- func (this *Ztime) SetLocation(timezone string) *Ztime
- func (this *Ztime) String() (string, error)
- func (this *Ztime) UTC() *Ztime
- func (this *Ztime) UnixNano(length int) string
Constants ¶
View Source
const ( OnDay = iota OnHour OnMin OnSecond )
Variables ¶
This section is empty.
Functions ¶
func GetCurrentDayOfMonth ¶
GetCurrentDayOfMonth 获取给定的时间是当月的第几天
func OnTimer ¶
OnTimer 定时发生器 OnDay 每天零时执行callback OnHour 每个小时执行callback OnMin 每分钟执行callback OnSecond 每秒钟执行callback 如果执行过程出现error, 则通过chan error获取具体错误原因
##### Example
```go //定时每天执行callback函数 package main
import (
"github.com/andy-zhangtao/gogather/zlog" "github.com/sirupsen/logrus" "github.com/andy-zhangtao/gogather/time"
)
var z *zlog.Zlog
func callback() error { logrus.WithFields(z.Fields(logrus.Fields{"from": "callback"})).Info("callback") return nil }
func main() { z = zlog.GetZlog() time.OnTimer(time.OnDay, 1, callback) }
```
Types ¶
type Ztime ¶
type Ztime struct {
// contains filtered or unexported fields
}
func (*Ztime) AddHour ¶
AddHour 以小时为单位调整时间
##### Example
```go
new(Ztime).Now().SetLocation("Asia/Shanghai").AddHour(-1).Format("2006-01-02T15:04")
```
func (*Ztime) AddMinute ¶
AddMinute 以分钟为单位调整时间
##### Example
```go
new(Ztime).Now().SetLocation("Asia/Shanghai").AddMinute(-1).Format("2006-01-02T15:04")
```
func (*Ztime) Format ¶
Format 设定时间格式 兼容官方Format格式. 同时支持YYYY-MM-DD hh:mm:ss格式
##### Example
```go
new(Ztime).Now().UTC().AddHour(7).Format("YYYY-MM-DDThh:mm")
```
func (*Ztime) SetLocation ¶
Click to show internal directories.
Click to hide internal directories.