TimeHelper

package
v1.1.168 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 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"
	UTFYEAR                = "2006"
	TTFALL_DATE_INT        = "20060102"
	UTFALL_DATE_INT_SECOND = "20060102150405"
)

Variables

View Source
var TIME_ERROR_ZERO = errors.New("empty time")

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 GetCstZone added in v1.1.48

func GetCstZone() *time.Location

func GetLastDayTimeStrUnderline

func GetLastDayTimeStrUnderline() string

* 获取昨天的日期 如: 当前时间为 2022-11-01 则返回:2022_10_31

func GetNowDayTimeStr

func GetNowDayTimeStr() string

* 获取当前时间的日期 如: 2022-11-01

func GetNowDayTimeStrUnderline

func GetNowDayTimeStrUnderline() string

* 获取当前时间的日期 如: 2022_11_01

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 GetTimeDateMonthBeginAndEnd added in v1.1.49

func GetTimeDateMonthBeginAndEnd(times time.Time) ([]string, error)

* 当前时间当前月的开始与结束日期

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

func TimeParseYear added in v1.1.167

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

* * 解析年字符串 * @param s string 时间日期字符串:2022

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 TimeParseUnixSecondToDate added in v1.1.47

func TimeParseUnixSecondToDate(unixTime int64) (*TimeHelper, error)

* 解析秒级时间戳到日期

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) ToMillisecond added in v1.1.46

func (t *TimeHelper) ToMillisecond() int64

* 获取时间毫秒

func (*TimeHelper) ToMinute

func (t *TimeHelper) ToMinute() string

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

func (*TimeHelper) ToMonth added in v1.1.166

func (t *TimeHelper) ToMonth() string

*

  • 日期月字符串
  • 2021-12

func (*TimeHelper) ToUnix added in v1.1.47

func (t *TimeHelper) ToUnix() int64

* 返回时间秒戳

func (*TimeHelper) WeekByDate

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

*

type TimeHelperReponseWeekDate added in v1.1.164

type TimeHelperReponseWeekDate struct {
	Year          int       // 年
	Month         int       // 月
	Day           int       // 日
	WeekAllNumber int       // 总年第几周
	StartTime     time.Time // 当周当月开始时间
	EndTime       time.Time // 当周当月结束时间
}

*

  • 响数据据返回当前时间的第几周及日期数据

func GetSubDateTimeStrWeekDate added in v1.1.164

func GetSubDateTimeStrWeekDate(timeData time.Time) *TimeHelperReponseWeekDate

*

  • 当前日期属于当前第几周,当月第几周及当前当前周开始时间

func NewTimeHelperResponseWeekDate added in v1.1.164

func NewTimeHelperResponseWeekDate(year int, month int, day int, allWeekNumber int, startTime time.Time, endTime time.Time) *TimeHelperReponseWeekDate

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