TimeHelper

package
v1.1.45 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: AGPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ANSIC                  = "Mon Jan _2 15:04:05 2006"
	UnixDate               = "Mon Jan _2 15:04:05 MST 2006"
	RubyDate               = "Mon Jan 02 15:04:05 -0700 2006"
	RFC822                 = "02 Jan 06 15:04 MST"
	RFC822Z                = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
	RFC850                 = "Monday, 02-Jan-06 15:04:05 MST"
	RFC1123                = "Mon, 02 Jan 2006 15:04:05 MST"
	RFC1123Z               = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
	RFC3339                = "2006-01-02T15:04:05Z07:00"
	RFC3339Nano            = "2006-01-02T15:04:05.999999999Z07:00"
	Kitchen                = "3:04PM"
	Stamp                  = "Jan _2 15:04:05"
	StampMilli             = "Jan _2 15:04:05.000"
	StampMicro             = "Jan _2 15:04:05.000000"
	StampNano              = "Jan _2 15:04:05.000000000"
	UTFALL_SECOND          = "2006-01-02 15:04:05"
	UTFALL_MINUTE          = "2006-01-02 15:04"
	UTFALL_HOUR_UNDERLINE  = "2006_01_02_15"
	UTFALL_HOUR            = "2006-01-02 15"
	UTFALL_DATE_UNDERLINE  = "2006_01_02"
	UTFALL_DATE            = "2006-01-02"
	UTFMONTH               = "2006-01"
	TTFALL_DATE_INT        = "20060102"
	UTFALL_DATE_INT_SECOND = "20060102150405"
)

Variables

This section is empty.

Functions

func AddDate added in v1.1.42

func AddDate(t time.Time, years, months, days int) time.Time

func GetArbitrarilyTimeStr

func GetArbitrarilyTimeStr(increment time.Duration) string

* 获取与当前时间计算后的值并返回字符串 2021-12-21 23:59:59

func GetLastDayTimeStrUnderline

func GetLastDayTimeStrUnderline() string

func GetNowDayTimeStr

func GetNowDayTimeStr() string

func GetNowDayTimeStrUnderline

func GetNowDayTimeStrUnderline() string

func GetNowTime

func GetNowTime() time.Time

* 获取当前时间

func GetNowTimeDate

func GetNowTimeDate() string

* 获取当前时间日期 2021-12-21

func GetNowTimeDateUnderline

func GetNowTimeDateUnderline() string

* 获取当前时间日期,用下划线分隔 2021_12_21

func GetNowTimeHourUnderline

func GetNowTimeHourUnderline() string

* 获取当前时间 日期+小时,用下划线分隔 2021_12_21_23

func GetNowTimeStr

func GetNowTimeStr() string

* 获取当前时间字符串 2021-12-21 23:59:59

func GetSubMonthDiffer added in v1.1.38

func GetSubMonthDiffer(max, min time.Time) (month int)

* 返回两个日期相差几个月 @param max time.Time @param min time.Time

func GetTimeDatePartition added in v1.1.21

func GetTimeDatePartition(startDate string, endDate string) ([]string, error)

* 获取两个日期间隔的日期明细 @param startDate string [true] 开始日期 [如:2022-06-14] @param endDate string [true] 结束日期 [如:2022-06-16]

@return []string{} exp: []string{2022-06-14, 2022-06-15, 2022-06-16}

func OverFormatTime

func OverFormatTime(formatTime string) string

* 时间过去计算 解析字符串日期格式 :Y-m-d H:i:s

func TimePare

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

* 解析时间字符串到时间戳 @param timeStr string 时间字符串:2021-12-21 23:59:59

func TimeParseDate

func TimeParseDate(s string) (time.Time, error)

* 解析时间日期字符串到时间戳 @param s string 时间日期字符串 : 2022-05-16

func TimeParseDateUnSeparator

func TimeParseDateUnSeparator(s string) (time.Time, error)

* 无字符串分隔 解析时间日期字符串到时间戳 @param string 时间日期字符串 : 20220516

func TimeParseMonth added in v1.1.43

func TimeParseMonth(s string) (time.Time, error)

* 解析日期字符串到时间戳 @param s string 日期字符串: 2022-05

Types

type TimeHelper

type TimeHelper struct {
	// contains filtered or unexported fields
}

func NewNowTime

func NewNowTime() *TimeHelper

func NewTime

func NewTime(time time.Time) *TimeHelper

* 时间格式初始化

func (*TimeHelper) GetDay

func (t *TimeHelper) GetDay() int

* 获取天

func (*TimeHelper) GetHour

func (t *TimeHelper) GetHour() int

* 获取小时

func (*TimeHelper) GetMinute

func (t *TimeHelper) GetMinute() int

* 获取分

func (*TimeHelper) GetMonth

func (t *TimeHelper) GetMonth() int

* 获取月

func (*TimeHelper) GetNextDayHour

func (t *TimeHelper) GetNextDayHour(hour int) *TimeHelper

* 获取第二天的指定小时

如当前为2022-03-20 12:00:00 传入hour 后 如:3 获取到的值为 2022-03-21 03:00:00

@param hour int 指定小时, 24小时制

func (*TimeHelper) GetNextDayHourTimeDuration

func (t *TimeHelper) GetNextDayHourTimeDuration(hour int) time.Duration

* 获取距离下一天指定小时还有多少时间 如当前为2022-03-20 00:10:00 传入hour 后 如:3 返回为 26h50m0s

@param hour int 指定小时, 24小时制

func (*TimeHelper) GetSecond

func (t *TimeHelper) GetSecond() int

* 获取秒

func (*TimeHelper) GetSubDay

func (t *TimeHelper) GetSubDay(day int) string

* 获取时间指定差积的时间[天] [逻辑] 1. 根据传入time 获取当前时间 2. 传day 获取间隔的天数, 如:

  1. 当前时间为: 2022-03-24, day: 1 则返回 2022-03-25
  2. 当前时间为: 2022-03-24, day: -1 赠返回 2022-03-23

@param day int 正负整数

func (*TimeHelper) GetSubDayTime

func (t *TimeHelper) GetSubDayTime(day int) time.Time

* 获取时间返回 时间戳 [逻辑] 1. 根据传入time 获取当前时间 2. 传day 获取间隔的天数, 如:

  1. 当前时间为: 2022-03-24, day: 1 则返回 2022-03-25 这里为time.Time
  2. 当前时间为: 2022-03-24, day: -1 赠返回 2022-03-23 这里为time.Time

@param day int 正负整数

func (*TimeHelper) GetSubMonth added in v1.1.37

func (t *TimeHelper) GetSubMonth(month int) string

* 获取时间指定差积的时间[月] [逻辑] 1. 根据传入time 获取当前时间 2. 传day 获取间隔的天数, 如:

  1. 当前时间为: 2022-03, day: 1 则返回 2022-02
  2. 当前时间为: 2022-03, day: -1 赠返回 2022-02

@param day int 正负整数

func (*TimeHelper) GetSubMonthTime added in v1.1.37

func (t *TimeHelper) GetSubMonthTime(month int) time.Time

* 获取上个月[月] 返回time [逻辑] 1. 根据传入time 获取当前时间 2. 传day 获取间隔的天数, 如:

  1. 当前时间为: 2022-03-06, day: 1 则返回 2022-02-06
  2. 当前时间为: 2022-03-06, day: -1 赠返回 2022-02-06

@param month int 正负整数

func (*TimeHelper) GetTime

func (t *TimeHelper) GetTime() time.Time

* 获取时间 time

func (*TimeHelper) GetWeekDay

func (t *TimeHelper) GetWeekDay() *TimeWeek

* 获取星期

func (*TimeHelper) GetYear

func (t *TimeHelper) GetYear() int

* 获取年

func (*TimeHelper) ToAll

func (t *TimeHelper) ToAll() string

* 返回时间字符串 2021-12-21 23:59:59

func (*TimeHelper) ToDate

func (t *TimeHelper) ToDate() string

* 获取日期字符串 2021-12-21

func (*TimeHelper) ToDateIntStr

func (t *TimeHelper) ToDateIntStr() string

* 获取日期字符串(无符号) 20220320

func (*TimeHelper) ToDateSecondIntStr added in v1.1.36

func (t *TimeHelper) ToDateSecondIntStr() string

* 获取当前时间字符串(精到秒 无符号)

func (*TimeHelper) ToDateUnderLine

func (t *TimeHelper) ToDateUnderLine() string

* 获取日期字符串,用下划线分隔 2021_12_21

func (*TimeHelper) ToHour

func (t *TimeHelper) ToHour() string

* 获取小时 2021-12-21 23

func (*TimeHelper) ToHourUnderLine

func (t *TimeHelper) ToHourUnderLine() string

* 获取小时,用下划线分隔 2021_12_21_23

func (*TimeHelper) ToMinute

func (t *TimeHelper) ToMinute() string

* 获取分 2021-12-21 23:59

func (*TimeHelper) WeekByDate

func (t *TimeHelper) WeekByDate(time time.Time) *TimeWeek

*

type TimeWeek

type TimeWeek struct {
	Year    int
	Month   int
	Weekday int
}

Jump to

Keyboard shortcuts

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