timeex

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 本地时间格式
	MsecLocalTimeFormat   = "2006-01-02 15:04:05.000"
	SecLocalTimeFormat    = "2006-01-02 15:04:05"
	MinuteLocalTimeFormat = "2006-01-02 15:04"
	HourLocalTimeFormat   = "2006-01-02 15"
	DateLocalTimeFormat   = "2006-01-02"
	MonthLocalTimeFormat  = "2006-01"
	TimeLocalTimeFormat   = "15:04:05"
	YearLocalTimeFormat   = "2006"
	TimeLocation          = "Asia/Shanghai"
	TimeLayout            = "2006-01-02 15:04"

	// DateTimeStartFormat ...
	DateTimeStartFormat = "2006-01-02 00:00:00"

	// DateTimeEndFormat ...
	DateTimeEndFormat = "2006-01-02 23:59:59"
)
View Source
const (
	// 格式:2006-01-02
	YYYY_MM_DD = "2006-01-02"
	// 格式:2006/01/02
	DATE_DIR_PATTERN    = "2006/01/02"
	YYYY_MM_DD_HH_MM_SS = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func CeilingTimeNow added in v0.0.8

func CeilingTimeNow() time.Time

CeilingTimeNow returns the current time from the range [now,now+100ms).

This is a faster alternative to time.Now().

func CountDaysOfMonth added in v0.0.9

func CountDaysOfMonth(year int, month int) (days int)

func CurrentTimeFormat added in v0.0.2

func CurrentTimeFormat() string

GetDate 获取字符串日期

func CurrentTimeLayout added in v0.0.2

func CurrentTimeLayout(layout string) string

func CurrentTimeMicrosecond added in v0.0.2

func CurrentTimeMicrosecond() int64

获取当前的时间的微妙

func CurrentTimeMillisecond added in v0.0.2

func CurrentTimeMillisecond() int64

获取当前时间的毫秒

func CurrentTimeNanosecond added in v0.0.2

func CurrentTimeNanosecond() int64

获取当前的时间的纳秒

func CurrentTimeSecond added in v0.0.2

func CurrentTimeSecond() int64

获取当前的秒数

func CurrentYear added in v0.0.2

func CurrentYear() string

func DateStrSubDays3 added in v0.0.9

func DateStrSubDays3(start, end string) (int, error)

DateStrSubDays3 end-start返回天数 日期格式: yyyy-mm-dd

func DateSubReturnDays added in v0.0.9

func DateSubReturnDays(start, end time.Time) (int, error)

DateSubReturnDays end-start返回天数

func FirstDayOfCurrentYearAsString added in v0.0.9

func FirstDayOfCurrentYearAsString() string

FirstDayOfCurrentYearAsString 返回今年的第一天,格式为 2019-01-01

func FloorTimeNow added in v0.0.8

func FloorTimeNow() time.Time

FloorTimeNow returns the current time from the range (now-100ms,now].

This is a faster alternative to time.Now().

func FormatDate added in v0.0.9

func FormatDate(date time.Time, format string) string

FormatDate 将日期转换成指定格式的字符串

func FormatDate1 added in v0.0.9

func FormatDate1(date time.Time) string

FormatDate1 日期转换成字符串 转换成: yyyymmdd

func FormatDate2 added in v0.0.9

func FormatDate2(date time.Time) string

FormatDate2 日期转换成字符串 转换成: yyyy/mm/dd

func FormatDate3 added in v0.0.9

func FormatDate3(date time.Time) string

FormatDate3 日期转换成字符串 转换成: yyyy-mm-dd

func FormatDate4 added in v0.0.9

func FormatDate4(date time.Time) string

FormatDate4 日期转换成字符串 转换成: yyyy-mm-dd mm:ss:ss

func FormatTime

func FormatTime(tm time.Time, forStr string) string

FormatTime 格式化时间

func Future

func Future(sec int, f func())

func GetBeginTimeToday added in v0.0.2

func GetBeginTimeToday() time.Time

获取今天零点的时间

func GetDateAsDefaultStr added in v0.0.9

func GetDateAsDefaultStr() string

GetDateAsDefaultStr 获取当前日期,格式 yyyy-mm-dd

func GetDay0

func GetDay0(timestamp int64) time.Time

GetDay0 获取给定日期的零点时间

func GetDayStr

func GetDayStr(tm time.Time) string

GetDayStr 获取日期字符串

func GetEndtime

func GetEndtime(format string) time.Time

func GetHour

func GetHour(timestamp int64) int

GetHour 当前时间向上取整点

func GetHour0

func GetHour0(timestamp int64) time.Time

GetHour0 获取向上整时时间

func GetLastDayCurrentTime

func GetLastDayCurrentTime(timestamp int64, offset int) time.Time

GetLastDayCurrentTime 获取offset天的现在时间:注意时区

func GetLastMonthStartAndEnd added in v0.0.9

func GetLastMonthStartAndEnd() (time.Time, time.Time)

GetLastMonthStartAndEnd 获取上月开始第一天和最后一天

func GetLocalTime

func GetLocalTime(tm time.Time) time.Time

GetLocalTime 获取本地时间

func GetMonth0

func GetMonth0(timestamp int64) time.Time

GetMonth0 获取给定时间的当月1号零点时间

func GetShowTime

func GetShowTime(ts time.Time) string

GetShowTime 格式化时间

func GetSysTimeLayout

func GetSysTimeLayout() string

GetSysTimeLayout 获取系统时间的格式

func GetTimeStr

func GetTimeStr(tm time.Time) string

GetTimeStr 获取时间字符串

func GetTimeWeek

func GetTimeWeek(timestamp int64) int

GetTimeWeek 获取给定时间的星期

func GetUtcDay0

func GetUtcDay0(now time.Time, timeZone *time.Location) int64

GetUtcDay0 获取offset 0点时间

func GetUtcTime

func GetUtcTime(tm time.Time) int64

GetUtcTime 获取本地时间戳

func GetUtcWeek0

func GetUtcWeek0(timestamp int64) int64

GetUtcWeek0 获取最近上个星期天的零点日期

func GetWeek0

func GetWeek0(timestamp int64) time.Time

GetWeek0 获取最近上个星期天的零点日期

func IsDate3 added in v0.0.9

func IsDate3(date string) (bool, error)

IsDate3 判断字符串格式是否是:yyyy-mm-dd

func ParseDate added in v0.0.9

func ParseDate(date string, format string) (time.Time, error)

ParseDate ParseDate 将字符串日期转换成日期

func ParseDate1 added in v0.0.9

func ParseDate1(date string) (time.Time, error)

ParseDate1 字符串转日期 字符串格式: yyyymmdd

func ParseDate2 added in v0.0.9

func ParseDate2(date string) (time.Time, error)

ParseDate2 字符串转日期 字符串格式: yyyy/mm/dd

func ParseDate3 added in v0.0.9

func ParseDate3(date string) (time.Time, error)

ParseDate3 字符串转日期 字符串格式: yyyy-mm-dd

func ParseTime added in v0.0.2

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

func SecondsToTimesStr1 added in v0.0.9

func SecondsToTimesStr1(seconds int) string

SecondsToTimesStr1 将秒转化成 天时分 格式 最终格式: 1天10时5分

func SecondsToTimesStr2 added in v0.0.9

func SecondsToTimesStr2(seconds int) string

SecondsToTimesStr2 将秒转化成时间格式 最终格式: 00:00:00

func StrToTime

func StrToTime(tStr, format string, timeZone *time.Location) time.Time

StrToTime 字符串转时间

func StringTimetoUnix

func StringTimetoUnix(timestr string) int64

StringTimetoUnix 给定字符串时间转换成本地时间戳

func Time2Unix

func Time2Unix(t time.Time) int64

注意把time转换成unix的时候有精度损失,只返回了秒值,没有用到纳秒值

func Time2UnixNano

func Time2UnixNano(t time.Time) int64

func TimeDayDuratioin

func TimeDayDuratioin(day float64) time.Duration

func TimeHourDuratioin

func TimeHourDuratioin(hour float64) time.Duration

func TimeMicrosecondDuration

func TimeMicrosecondDuration(m float64) time.Duration

微秒

func TimeMillisecondDuration

func TimeMillisecondDuration(m float64) time.Duration

毫秒

func TimeMinuteDuration

func TimeMinuteDuration(minute float64) time.Duration

func TimeNanosecondDuration

func TimeNanosecondDuration(n float64) time.Duration

纳秒

func TimeSecondDuration

func TimeSecondDuration(sec float64) time.Duration

func TimeStrSub added in v0.0.9

func TimeStrSub(start, end, format string) (int64, error)

TimeStrSub 日期字符串相减 end-start 返回int

func TimeToShortString

func TimeToShortString(ts time.Time) string

TimeToShortString 时间转日期

func TimeToString

func TimeToString(ts time.Time) string

TimeToString 时间转字符串

func TimerByHour

func TimerByHour(f func())

TimerByHour 整点执行操作

func Unix2Time

func Unix2Time(unix int64) time.Time

func UnixNano2Time

func UnixNano2Time(nano int64) time.Time

func UnixString2Time

func UnixString2Time(unix string) (time.Time, error)

func UnixToTime

func UnixToTime(timestamp int64) time.Time

UnixToTime 时间戳转换为time

func YMD

func YMD(year int, month int, day int, hour int, minute int, sec int) int

func YMDPrint

func YMDPrint(sec int, nsec int) string

func YMDUTC

func YMDUTC(year int, month int, day int, hour int, minute int, sec int) int

Types

type Date added in v0.0.7

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

Date ...

func NewDate added in v0.0.7

func NewDate(opts ...DateHandler) *Date

NewDate init Date struct if len(opts)=0, the base time is time.Now()

func (*Date) LastMonthEndDate added in v0.0.7

func (d *Date) LastMonthEndDate() string

LastMonthEndDate ...

func (*Date) LastMonthEndDateTime added in v0.0.7

func (d *Date) LastMonthEndDateTime() string

LastMonthEndDateTime ...

func (*Date) LastMonthStartDate added in v0.0.7

func (d *Date) LastMonthStartDate() string

LastMonthStartDate ...

func (*Date) LastMonthStartDateTime added in v0.0.7

func (d *Date) LastMonthStartDateTime() string

LastMonthStartDateTime ...

func (*Date) LastWeekEndDate added in v0.0.7

func (d *Date) LastWeekEndDate() string

LastWeekEndDate ...

func (*Date) LastWeekEndDateTime added in v0.0.7

func (d *Date) LastWeekEndDateTime() string

LastWeekEndDateTime ...

func (*Date) LastWeekStartDate added in v0.0.7

func (d *Date) LastWeekStartDate() string

LastWeekStartDate ...

func (*Date) LastWeekStartDateTime added in v0.0.7

func (d *Date) LastWeekStartDateTime() string

LastWeekStartDateTime ...

func (*Date) LastYearEndDate added in v0.0.7

func (d *Date) LastYearEndDate() string

LastYearEndDate ...

func (*Date) LastYearEndDateTime added in v0.0.7

func (d *Date) LastYearEndDateTime() string

LastYearEndDateTime ...

func (*Date) LastYearStartDate added in v0.0.7

func (d *Date) LastYearStartDate() string

LastYearStartDate ...

func (*Date) LastYearStartDateTime added in v0.0.7

func (d *Date) LastYearStartDateTime() string

LastYearStartDateTime ...

func (*Date) MonthStartDate added in v0.0.7

func (d *Date) MonthStartDate() string

MonthStartDate ...

func (*Date) MonthStartDateTime added in v0.0.7

func (d *Date) MonthStartDateTime() string

MonthStartDateTime ...

func (*Date) TodayDate added in v0.0.7

func (d *Date) TodayDate() string

TodayDate ...

func (*Date) TodayDateTime added in v0.0.7

func (d *Date) TodayDateTime() string

TodayDateTime ...

func (*Date) TodayEndDateTime added in v0.0.7

func (d *Date) TodayEndDateTime() string

TodayEndDateTime ...

func (*Date) TodayStartDateTime added in v0.0.7

func (d *Date) TodayStartDateTime() string

TodayStartDateTime ...

func (*Date) TomorrowDate added in v0.0.7

func (d *Date) TomorrowDate() string

TomorrowDate ...

func (*Date) TomorrowEndDateTime added in v0.0.7

func (d *Date) TomorrowEndDateTime() string

TomorrowEndDateTime ...

func (*Date) TomorrowStartDateTime added in v0.0.7

func (d *Date) TomorrowStartDateTime() string

TomorrowStartDateTime ...

func (*Date) WeekStartDate added in v0.0.7

func (d *Date) WeekStartDate() string

WeekStartDate ...

func (*Date) YearStartDate added in v0.0.7

func (d *Date) YearStartDate() string

YearStartDate ...

func (*Date) YearStartDateTime added in v0.0.7

func (d *Date) YearStartDateTime() string

YearStartDateTime ...

func (*Date) YesterdayDate added in v0.0.7

func (d *Date) YesterdayDate() string

YesterdayDate ...

func (*Date) YesterdayEndDateTime added in v0.0.7

func (d *Date) YesterdayEndDateTime() string

YesterdayEndDateTime ...

func (*Date) YesterdayStartDateTime added in v0.0.7

func (d *Date) YesterdayStartDateTime() string

YesterdayStartDateTime ...

type DateHandler added in v0.0.7

type DateHandler func(d *Date)

DateHandler ...

func BindDate added in v0.0.7

func BindDate(dateStr string) DateHandler

func BindDateTime added in v0.0.7

func BindDateTime(datetimeStr string) DateHandler

func BindTime added in v0.0.7

func BindTime(dateObj time.Time) DateHandler

BindTime bind time.Time type as base time

type GoTime added in v0.0.8

type GoTime struct {
	time.Time
}

func New added in v0.0.8

func New() GoTime

func NewWithDateString added in v0.0.8

func NewWithDateString(d string) GoTime

func NewWithDateTimeString added in v0.0.8

func NewWithDateTimeString(dt string) GoTime

func NewWithTime added in v0.0.8

func NewWithTime(t time.Time) GoTime

func Now

func Now() GoTime

func (GoTime) FormatDateString added in v0.0.8

func (d GoTime) FormatDateString() string

FormatDateString

func (GoTime) FormatDateTimeEndString added in v0.0.8

func (d GoTime) FormatDateTimeEndString() string

FormatDateTimeEndString

func (GoTime) FormatDateTimeStartString added in v0.0.8

func (d GoTime) FormatDateTimeStartString() string

FormatDateTimeStartString

func (GoTime) FormatDateTimeString added in v0.0.8

func (d GoTime) FormatDateTimeString() string

FormatDateTimeString

func (GoTime) LastMonth added in v0.0.8

func (d GoTime) LastMonth() GoTime

LastMonth

func (GoTime) LastMonthEnd added in v0.0.8

func (d GoTime) LastMonthEnd() GoTime

LastMonthEnd

func (GoTime) LastMonthStart added in v0.0.8

func (d GoTime) LastMonthStart() GoTime

LastMonthStart

func (GoTime) LastWeek added in v0.0.8

func (d GoTime) LastWeek() GoTime

LastWeek ...

func (GoTime) LastWeekEnd added in v0.0.8

func (d GoTime) LastWeekEnd() GoTime

LastWeekEnd ...

func (GoTime) LastWeekStart added in v0.0.8

func (d GoTime) LastWeekStart() GoTime

LastWeekStart ...

func (GoTime) LastYear added in v0.0.8

func (d GoTime) LastYear() GoTime

LastYear

func (GoTime) LastYearEnd added in v0.0.8

func (d GoTime) LastYearEnd() GoTime

LastYearEnd

func (GoTime) LastYearStart added in v0.0.8

func (d GoTime) LastYearStart() GoTime

LastYearStart

func (GoTime) MonthEnd added in v0.0.8

func (d GoTime) MonthEnd() GoTime

MonthEnd

func (GoTime) MonthStart added in v0.0.8

func (d GoTime) MonthStart() GoTime

MonthStart

func (GoTime) NextMonth added in v0.0.8

func (d GoTime) NextMonth() GoTime

NextMonth

func (GoTime) NextMonthAfterStart added in v0.0.8

func (d GoTime) NextMonthAfterStart() GoTime

NextMonthAfterStart

func (GoTime) NextMonthEnd added in v0.0.8

func (d GoTime) NextMonthEnd() GoTime

NextMonthEnd

func (GoTime) NextMonthStart added in v0.0.8

func (d GoTime) NextMonthStart() GoTime

NextMonthStart

func (GoTime) NextWeek added in v0.0.8

func (d GoTime) NextWeek() GoTime

NextWeek ...

func (GoTime) NextWeekEnd added in v0.0.8

func (d GoTime) NextWeekEnd() GoTime

NextWeekEnd ...

func (GoTime) NextWeekStart added in v0.0.8

func (d GoTime) NextWeekStart() GoTime

NextWeekStart ...

func (GoTime) NextYear added in v0.0.8

func (d GoTime) NextYear() GoTime

NextYear

func (GoTime) NextYearAfterStart added in v0.0.8

func (d GoTime) NextYearAfterStart() GoTime

NextYearAfterStart

func (GoTime) NextYearEnd added in v0.0.8

func (d GoTime) NextYearEnd() GoTime

NextYearEnd

func (GoTime) NextYearStart added in v0.0.8

func (d GoTime) NextYearStart() GoTime

NextYearStart

func (GoTime) Tomorrow added in v0.0.8

func (d GoTime) Tomorrow() GoTime

Tomorrow ...

func (GoTime) WeekEnd added in v0.0.8

func (d GoTime) WeekEnd() GoTime

WeekEnd is this week of Sunday

func (GoTime) WeekStart added in v0.0.8

func (d GoTime) WeekStart() GoTime

WeekStart is this week of Monday

func (GoTime) YearEnd added in v0.0.8

func (d GoTime) YearEnd() GoTime

YearEnd

func (GoTime) YearStart added in v0.0.8

func (d GoTime) YearStart() GoTime

YearStart

func (GoTime) Yesterday added in v0.0.8

func (d GoTime) Yesterday() GoTime

Yesterday ...

type Time

type Time struct {
	time.Time
}

Time json marsh 重写

func (Time) MarshalJSON

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

MarshalJSON ...

func (Time) String

func (t Time) String() string

String ...

func (*Time) UnmarshalJSON

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

UnmarshalJSON ...

Jump to

Keyboard shortcuts

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