timex

package
v0.0.0-...-0b3bbd9 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LAYOUT_DATE_TIME = "2006-01-02 15:04:05" // 日期时间格式布局
	LAYOUT_DATE      = "2006-01-02 00:00:00" // 日期格式布局
	LAYOUT_TIME      = "2000-01-01 15:04:05" // 时间格式布局

	DATE_TIME_END = "2099-01-01 00:00:00" // 默认结束时间
)
View Source
const (
	ODateFormat = "2006-01-02"
)
View Source
const (
	ODateTimeFormat = "2006-01-02 15:04:05"
)
View Source
const OTimeFormat = "15:04:05"

Variables

View Source
var CHINESENUMBER = []string{"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"}
View Source
var CHINESENUMBERSPECIAL = []string{"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"}
View Source
var DATELAYOUT = "2006-01-02"
View Source
var LOC_ZONE = time.FixedZone("CST", 8*3600) // 东八区
View Source
var LUNAR_INFO = []int{}/* 150 elements not displayed */
View Source
var MAX_YEAR = 2049
View Source
var MIN_YEAR = 1900
View Source
var MONTHNUMBER = map[string]int{"January": 1, "February": 2, "March": 3, "April": 4, "May": 5, "June": 6, "July": 7, "August": 8, "September": 9, "October": 10, "November": 11, "December": 12}
View Source
var NTPs = []string{
	"cn.pool.ntp.org",
	"cn.ntp.org.cn",
	"edu.ntp.org.cn",
	"ntp.aliyun.com",
	"ntp1.aliyun.com",
	"ntp2.aliyun.com",
	"ntp3.aliyun.com",
	"ntp4.aliyun.com",
	"ntp5.aliyun.com",
	"ntp6.aliyun.com",
	"ntp7.aliyun.com",
	"hk.ntp.org.cn",
	"sgp.ntp.org.cn",
	"us.ntp.org.cn",
	"time.sunqida.cn",
}
View Source
var STARTDATESTR = "1900-01-30"

Functions

func Date

func Date(ti int64, format string) string

Format unix time int64 to string

func DateParse

func DateParse(dateString, format string) (time.Time, error)

Parse Date use PHP time format.

func DateT

func DateT(t time.Time, format string) string

Format time.Time struct to string MM - month - 01 M - month - 1, single bit DD - day - 02 D - day 2 YYYY - year - 2006 YY - year - 06 HH - 24 hours - 03 H - 24 hours - 3 hh - 12 hours - 03 h - 12 hours - 3 mm - minute - 04 m - minute - 4 ss - second - 05 s - second = 5

func DateToString

func DateToString(ts string, format string) string

Format unix time string to string

func GetBetweenDates

func GetBetweenDates(date_start, date_end time.Time) (d []time.Time)

func GetCountDown

func GetCountDown(t time.Time) string

倒计时

func GetDate

func GetDate(src time.Time) time.Time

func GetDateTime

func GetDateTime(date time.Time, src time.Time) (dst time.Time, _err error)

func GetDateTimeHour

func GetDateTimeHour(src time.Time) time.Time

获取日期时整数 2023-01-02T15:00:00+08:00

func GetDateTimeMinute

func GetDateTimeMinute(src time.Time) time.Time

获取日期分整数 2023-01-02T15:01:00+08:00

func GetFirstDateOfMonth

func GetFirstDateOfMonth(d time.Time) time.Time

获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。

func GetFirstDateOfWeek

func GetFirstDateOfWeek(d time.Time, start_sunday bool) time.Time

func GetFirstDateOfYear

func GetFirstDateOfYear(d time.Time) time.Time

获取传入的时间所在年第一天

func GetLastDateOfMonth

func GetLastDateOfMonth(d time.Time) time.Time

获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。

func GetMonthStartAndEnd

func GetMonthStartAndEnd(date time.Time) (time.Time, time.Time)

func GetZeroTimeOfDay

func GetZeroTimeOfDay(d time.Time) time.Time

获取某一天的0点时间

func IsToday

func IsToday(t time.Time) bool

判断输入时间是否为当天时间

func LgToday

func LgToday(t time.Time) bool

大于今天

func LtToday

func LtToday(t time.Time) bool

小于今天

func LunarToSolar

func LunarToSolar(date string, leapMonthFlag bool) (d string, err error)

func ParseWithLocation

func ParseWithLocation(timeStr string) (time.Time, error)

转为本地日期

func ServerNtp

func ServerNtp(port int)

默认123

func SolarToChineseLuanr

func SolarToChineseLuanr(date string) string

func SolarToLuanr

func SolarToLuanr(date string) (string, bool)

func SolarToSimpleLuanr

func SolarToSimpleLuanr(date string) string

func SyncNtp

func SyncNtp(server_ntp string)

func TimeNtpCompare

func TimeNtpCompare(date string) (err error)

data = "2021-10-01"

func TimeNullToTime

func TimeNullToTime(null_time TimeNull) time.Time

func TimeStringToTime

func TimeStringToTime(str_time string, loc_zone *time.Location) time.Time

func UpdateDate

func UpdateDate(src *time.Time) (_err error)

获取零时间 2023-01-01T00:00:00+08:00

func UpdateDateTimeHour

func UpdateDateTimeHour(src *time.Time) (_err error)

修改为日期整时 2023-01-02T15:00:00+08:00

func UpdateHour

func UpdateHour(src *time.Time) (_err error)

获取零日期整时 2000-01-01T15:00:00+08:00

func UpdateSystemDate

func UpdateSystemDate(server_ntp, dateTime string) bool

func UpdateTime

func UpdateTime(src *time.Time) (_err error)

获取零日期 舍去秒 2000-01-01T15:04:00+08:00

Types

type ITimer

type ITimer interface {
	AddTaskByFunc(taskName string, spec string, task func(), option ...cron.Option) (cron.EntryID, error)
	AddTaskByJob(taskName string, spec string, job interface{ Run() }, option ...cron.Option) (cron.EntryID, error)
	FindCron(taskName string) (*cron.Cron, bool)
	StartTask(taskName string)
	StopTask(taskName string)
	Remove(taskName string, id int)
	Clear(taskName string)
	Close()
}

func NewTimerTask

func NewTimerTask() ITimer

type LcTimer

type LcTimer struct {
	TaskList map[string]*cron.Cron
	sync.Mutex
}

定时任务管理

func (*LcTimer) AddTaskByFunc

func (t *LcTimer) AddTaskByFunc(taskName string, spec string, task func(), option ...cron.Option) (cron.EntryID, error)

通过函数创建方法添加任务

func (*LcTimer) AddTaskByJob

func (t *LcTimer) AddTaskByJob(taskName string, spec string, job interface{ Run() }, option ...cron.Option) (cron.EntryID, error)

通过接口方式批量添加任务

func (*LcTimer) Clear

func (t *LcTimer) Clear(taskName string)

func (*LcTimer) Close

func (t *LcTimer) Close()

func (*LcTimer) FindCron

func (t *LcTimer) FindCron(taskName string) (*cron.Cron, bool)

根据名称获取对应的cron

func (*LcTimer) Remove

func (t *LcTimer) Remove(taskName string, id int)

移除指定的定时任务

func (*LcTimer) StartTask

func (t *LcTimer) StartTask(taskName string)

开始定时任务

func (*LcTimer) StopTask

func (t *LcTimer) StopTask(taskName string)

停止定时任务

type ODate

type ODate struct {
	time.Time
}

func NewODate

func NewODate(date string) ODate

func (ODate) MarshalJSON

func (t ODate) MarshalJSON() ([]byte, error)

func (*ODate) Scan

func (t *ODate) Scan(v interface{}) error

func (*ODate) UnmarshalJSON

func (t *ODate) UnmarshalJSON(data []byte) (_err error)

func (ODate) Value

func (t ODate) Value() (driver.Value, error)

type ODateTime

type ODateTime struct {
	time.Time
}

func (ODateTime) MarshalJSON

func (t ODateTime) MarshalJSON() ([]byte, error)

func (*ODateTime) Scan

func (t *ODateTime) Scan(v interface{}) error

func (*ODateTime) UnmarshalJSON

func (t *ODateTime) UnmarshalJSON(data []byte) (_err error)

func (ODateTime) Value

func (t ODateTime) Value() (driver.Value, error)

type OTime

type OTime struct {
	time.Time
}

func NewOTime

func NewOTime(date string) OTime

func (OTime) Add

func (t OTime) Add(td time.Duration) OTime

func (*OTime) IsNull

func (t *OTime) IsNull() bool

func (OTime) MarshalJSON

func (t OTime) MarshalJSON() ([]byte, error)

func (*OTime) Scan

func (t *OTime) Scan(v interface{}) error

func (*OTime) UnmarshalJSON

func (t *OTime) UnmarshalJSON(data []byte) (err error)

func (OTime) Value

func (t OTime) Value() (driver.Value, error)

type TimeNull

type TimeNull struct {
	sql.NullTime
}

func TimeNullNow

func TimeNullNow() TimeNull

func TimeStringToTimeNull

func TimeStringToTimeNull(str_time string, loc_zone *time.Location) TimeNull

func TimeToTimeNull

func TimeToTimeNull(t time.Time) TimeNull

func UpdateTimeNull

func UpdateTimeNull(t time.Time) TimeNull

func (TimeNull) Add

func (v TimeNull) Add(time_long time.Duration) TimeNull

func (TimeNull) MarshalJSON

func (v TimeNull) MarshalJSON() ([]byte, error)

func (*TimeNull) Now

func (v *TimeNull) Now() TimeNull

func (*TimeNull) UnmarshalJSON

func (v *TimeNull) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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