Documentation
¶
Index ¶
- Constants
- Variables
- func DayDifferenceHours(startDate, endDate string) float64
- func DaySecondsDifferenceHours(startSecond, endSecond int64) float64
- func DayTimeDifferenceHours(startDate, endDate time.Time) float64
- func DurationHMS(d time.Duration) (int, int, int)
- func DurationToDurationpb(duration *time.Duration) *durationpb.Duration
- func DurationpbToDuration(duration *durationpb.Duration) *time.Duration
- func DurationpbToFloat(duration *durationpb.Duration, timePrecision time.Duration) *float64
- func DurationpbToNumber[...](duration *durationpb.Duration, timePrecision time.Duration) *T
- func DurationpbToSecond(duration *durationpb.Duration) *float64
- func DurationpbToString(in *durationpb.Duration) *string
- func Float64ToDurationpb(d float64) *durationpb.Duration
- func FloatToDurationpb(duration *float64, timePrecision time.Duration) *durationpb.Duration
- func FormatTimeMulti(dateFormat string, v any) string
- func FormatTimeToString(format string) func(time.Time) string
- func FormatTimer(d time.Duration) string
- func FormatTimerf(format string, d time.Duration) string
- func FromTo(value, fromLayout, toLayout string) (string, error)
- func FromTo2(fromLayout, toLayout, value string) (string, error)
- func FromToFirstValue(fromLayout, toLayout string, values []string) (string, error)
- func FromToFirstValueOrEmpty(fromLayout, toLayout string, values []string) string
- func GetCurrentMonthRangeDateString() (string, string)
- func GetCurrentMonthRangeTime() (time.Time, time.Time)
- func GetCurrentMonthRangeTimeString() (string, string)
- func GetCurrentYearRangeDateString() (string, string)
- func GetCurrentYearRangeTime() (time.Time, time.Time)
- func GetCurrentYearRangeTimeString() (string, string)
- func GetDefaultTimeLocation() *time.Location
- func GetFormat(formatName string) (string, error)
- func GetLastMonthRangeDateString() (string, string)
- func GetLastMonthRangeTime() (time.Time, time.Time)
- func GetLastMonthRangeTimeString() (string, string)
- func GetLastYearRangeDateString() (string, string)
- func GetLastYearRangeTime() (time.Time, time.Time)
- func GetLastYearRangeTimeString() (string, string)
- func GetTodayRangeDateString() (string, string)
- func GetTodayRangeTime() (time.Time, time.Time)
- func GetTodayRangeTimeString() (string, string)
- func GetYesterdayRangeDateString() (string, string)
- func GetYesterdayRangeTime() (time.Time, time.Time)
- func GetYesterdayRangeTimeString() (string, string)
- func IsDTX(d int) (string, error)
- func MicrosecondsToTimestamp(microseconds *int64) *timestamppb.Timestamp
- func MillisecondsToTimestamp(milliseconds *int64) *timestamppb.Timestamp
- func NanosecondsToTimestamp(nanoseconds *int64) *timestamppb.Timestamp
- func NumberToDurationpb[...](duration *T, timePrecision time.Duration) *durationpb.Duration
- func OffsetFormat(offset int, useColon, useZ bool) string
- func ParseFirst(layouts []string, value string) (time.Time, error)
- func ParseFirstValue(layout string, values []string) (time.Time, error)
- func ParseFirstValueOrZero(layout string, values []string) time.Time
- func ParseOrZero(layout, value string) time.Time
- func ParseSlice(layout string, strings []string) ([]time.Time, error)
- func ParseTimeSQLTimestampUsingOffset(timeStr string, offset int) (time.Time, error)
- func ParseTimeUsingOffset(format, raw, sep string, offset int, useColon, useZ bool) (time.Time, error)
- func RangeStringDateToTime(startDate, endDate string) (time.Time, time.Time)
- func ReferenceTime() time.Time
- func RefreshDefaultTimeLocation(name string) *time.Location
- func SecondToDurationpb(seconds *float64) *durationpb.Duration
- func SecondsDifferenceDays(startSecond, endSecond int64) int
- func SecondsToTimestamp(seconds *int64) *timestamppb.Timestamp
- func StringDateToTime(str *string) *time.Time
- func StringDifferenceDays(startDate, endDate string) int
- func StringTimeToTime(str *string) *time.Time
- func StringToDurationpb(in *string) *durationpb.Duration
- func StringToTime(str *string, layout string) *time.Time
- func StringToTimestamppb(str *string) *timestamppb.Timestamp
- func StringToUnixMilliInt64Ptr(tm *string) *int64
- func TimeDifferenceDays(startDate, endDate time.Time) int
- func TimeMinRFC3339() time.Time
- func TimeToDateString(tm *time.Time) *string
- func TimeToString(tm *time.Time, layout string) *string
- func TimeToTimeString(tm *time.Time) *string
- func TimeToTimestamppb(tm *time.Time) *timestamppb.Timestamp
- func TimeToUnixMilliInt64Ptr(tm *time.Time) *int64
- func TimeToUnixSecondInt64Ptr(tm *time.Time) *int64
- func TimeZeroRFC3339() time.Time
- func TimeZeroUnix() time.Time
- func TimestampToMicroseconds(ts *timestamppb.Timestamp) int64
- func TimestampToMilliseconds(ts *timestamppb.Timestamp) int64
- func TimestampToNanoseconds(ts *timestamppb.Timestamp) int64
- func TimestampToSeconds(ts *timestamppb.Timestamp) int64
- func TimestamppbToString(ts *timestamppb.Timestamp) *string
- func TimestamppbToTime(timestamp *timestamppb.Timestamp) *time.Time
- func UnixMilliToStringPtr(milli *int64) *string
- func UnixMilliToTimePtr(milli *int64) *time.Time
- func UnixSecondToTimePtr(second *int64) *time.Time
- type ISO8601NoTzMilliTime
- type RFC3339YMDTime
Constants ¶
const ( DateLayout = "2006-01-02" ClockLayout = "15:04:05" TimeLayout = DateLayout + " " + ClockLayout DefaultTimeLocationName = "Asia/Shanghai" )
const ( DT14 = "20060102150405" DT8 = "20060102" DT8MDY = "01022006" DT6 = "200601" MonthDay = "1/2" DIN5008FullDate = "02.01.2006" // German DIN 5008 standard DIN5008Date = "02.01.06" RFC3339FullDate = time.DateOnly RFC3339Milli = "2006-01-02T15:04:05.999Z07:00" RFC3339Dash = "2006-01-02T15-04-05Z07-00" ISO8601 = "2006-01-02T15:04:05Z0700" ISO8601TZHour = "2006-01-02T15:04:05Z07" ISO8601NoTZ = "2006-01-02T15:04:05" ISO8601MilliNoTZ = "2006-01-02T15:04:05.999" ISO8601Milli = "2006-01-02T15:04:05.999Z0700" ISO8601CompactZ = "20060102T150405Z0700" ISO8601CompactNoTZ = "20060102T150405" ISO8601YM = "2006-01" ISO9075 = time.DateTime // ISO/IEC 9075 used by MySQL, BigQuery, etc. ISO9075MicroTZ = "2006-01-02 15:04:05.999999-07" // ISO/IEC 9075 used by PostgreSQL RFC5322 = "Mon, 2 Jan 2006 15:04:05 -0700" // RFC5322 = "Mon Jan 02 15:04:05 -0700 2006" SQLTimestamp = ISO9075 SQLTimestampMinutes = "2006-01-02 15:04" Ruby = "2006-01-02 15:04:05 -0700" // Ruby Time.now.to_s InsightlyAPIQuery = "_1/_2/2006 _3:04:05 PM" DateMDY = "1/2/2006" // an underscore results in a space. DateMDYSlash = "01/02/2006" DateDMYDash = "_2-01-2006" // Jira XML Date format DateDMYHM2 = "02:01:06 15:04" // GMT time in format dd:mm:yy hh:mm DateYMD = RFC3339FullDate DateTextUS = "January 2, 2006" DateTextUSAbbr3 = "Jan 2, 2006" DateTextEU = "2 January 2006" DateTextEUAbbr3 = "2 Jan 2006" MonthAbbrYear = "Jan 2006" MonthYear = "January 2006" )
More predefined layouts for use in Time.Format and time.Parse.
const ( RFC3339Min = "0000-01-01T00:00:00Z" RFC3339Max = "9999-12-31T23:59:59Z" RFC3339Zero = "0001-01-01T00:00:00Z" // Golang zero value RFC3339ZeroUnix = "1970-01-01T00:00:00Z" RFC3339YMDZeroUnix = int64(-62135596800) )
const ( LayoutNameDT4 = "dt4" LayoutNameDT6 = "dt6" LayoutNameDT8 = "dt8" LayoutNameDT14 = "dt14" )
Variables ¶
var FormatMap = map[string]string{ "RFC3339": time.RFC3339, "RFC3339YMD": RFC3339FullDate, "ISO8601YM": ISO8601YM, }
Functions ¶
func DayDifferenceHours ¶
DayDifferenceHours 两天之间相差了多少小时
func DayTimeDifferenceHours ¶
func DurationHMS ¶
DurationHMS Extracts the hours, minutes, and seconds from the given duration.
func DurationToDurationpb ¶ added in v1.1.15
func DurationToDurationpb(duration *time.Duration) *durationpb.Duration
func DurationpbToDuration ¶ added in v1.1.15
func DurationpbToDuration(duration *durationpb.Duration) *time.Duration
func DurationpbToFloat ¶ added in v1.1.14
func DurationpbToFloat(duration *durationpb.Duration, timePrecision time.Duration) *float64
func DurationpbToNumber ¶ added in v1.1.14
func DurationpbToSecond ¶ added in v1.1.23
func DurationpbToSecond(duration *durationpb.Duration) *float64
func DurationpbToString ¶ added in v1.1.23
func DurationpbToString(in *durationpb.Duration) *string
func Float64ToDurationpb ¶ added in v1.1.20
func Float64ToDurationpb(d float64) *durationpb.Duration
func FloatToDurationpb ¶ added in v1.1.14
func FloatToDurationpb(duration *float64, timePrecision time.Duration) *durationpb.Duration
func FormatTimeMulti ¶ added in v1.1.24
FormatTimeMulti formats a `time.Time` object or an epoch number. It is adapted from `github.com/wcharczuk/go-chart`.
func FormatTimeToString ¶ added in v1.1.24
func FormatTimer ¶
FormatTimer Formats the given duration in a colon-separated timer format in the form [HH:]MM:SS.
func FormatTimerf ¶
FormatTimerf Formats the given duration using the given format string. The string follows the same formatting rules as described in the fmt package, and will receive three integer arguments: hours, minutes, and seconds.
func FromToFirstValue ¶ added in v1.1.24
func FromToFirstValueOrEmpty ¶ added in v1.1.24
func GetCurrentMonthRangeDateString ¶
GetCurrentMonthRangeDateString 获取区间时间内的日期字符串(比如:2023-05-23 2023-05-23) - 本月
func GetCurrentMonthRangeTime ¶
GetCurrentMonthRangeTime 获取区间时间 - 本月
func GetCurrentMonthRangeTimeString ¶
GetCurrentMonthRangeTimeString 获取区间时间内的时间字符串(比如:2023-05-23 00:00:00 2023-05-23 23:59:59) - 本月
func GetCurrentYearRangeDateString ¶
GetCurrentYearRangeDateString 获取区间时间内的日期字符串(比如:2023-05-23 2023-05-23) - 今年
func GetCurrentYearRangeTime ¶
GetCurrentYearRangeTime 获取区间时间 - 今年
func GetCurrentYearRangeTimeString ¶
GetCurrentYearRangeTimeString 获取区间时间内的时间字符串(比如:2023-05-23 00:00:00 2023-05-23 23:59:59) - 今年
func GetDefaultTimeLocation ¶ added in v1.1.20
func GetLastMonthRangeDateString ¶
GetLastMonthRangeDateString 获取区间时间内的日期字符串(比如:2023-05-23 2023-05-23) - 上个月
func GetLastMonthRangeTime ¶
GetLastMonthRangeTime 获取区间时间 - 上个月
func GetLastMonthRangeTimeString ¶
GetLastMonthRangeTimeString 获取区间时间内的时间字符串(比如:2023-05-23 00:00:00 2023-05-23 23:59:59) - 上个月
func GetLastYearRangeDateString ¶
GetLastYearRangeDateString 获取区间时间内的日期字符串(比如:2023-05-23 2023-05-23) - 去年
func GetLastYearRangeTime ¶
GetLastYearRangeTime 获取区间时间 - 去年
func GetLastYearRangeTimeString ¶
GetLastYearRangeTimeString 获取区间时间内的时间字符串(比如:2023-05-23 00:00:00 2023-05-23 23:59:59) - 去年
func GetTodayRangeDateString ¶
GetTodayRangeDateString 获取区间时间内的日期字符串(比如:2023-05-23 2023-05-23) - 今天
func GetTodayRangeTime ¶
GetTodayRangeTime 获取区间时间 - 今天
func GetTodayRangeTimeString ¶
GetTodayRangeTimeString 获取区间时间内的时间字符串(比如:2023-05-23 00:00:00 2023-05-23 23:59:59) - 今天
func GetYesterdayRangeDateString ¶
GetYesterdayRangeDateString 获取区间时间内的日期字符串(比如:2023-05-23 2023-05-23) - 昨天
func GetYesterdayRangeTime ¶
GetYesterdayRangeTime 获取区间时间 - 昨天
func GetYesterdayRangeTimeString ¶
GetYesterdayRangeTimeString 获取区间时间内的时间字符串(比如:2023-05-23 00:00:00 2023-05-23 23:59:59) - 昨天
func IsDTX ¶ added in v1.1.24
IsDTX returns the dtx format if conformant to various DTX values (dt4, dt6, dt8, dt14).
func MicrosecondsToTimestamp ¶ added in v1.1.30
func MicrosecondsToTimestamp(microseconds *int64) *timestamppb.Timestamp
func MillisecondsToTimestamp ¶ added in v1.1.30
func MillisecondsToTimestamp(milliseconds *int64) *timestamppb.Timestamp
func NanosecondsToTimestamp ¶ added in v1.1.30
func NanosecondsToTimestamp(nanoseconds *int64) *timestamppb.Timestamp
NanosecondsToTimestamp 将纳秒转换为 timestamppb.Timestamp
func NumberToDurationpb ¶ added in v1.1.14
func OffsetFormat ¶ added in v1.1.24
OffsetFormat converts an integer offset value to a string value to use in string time formats. Note: RFC-3339 times use colons and the UTC "Z" offset.
func ParseFirst ¶ added in v1.1.24
ParseFirst attempts to parse a string with a set of layouts.
func ParseFirstValue ¶ added in v1.1.24
func ParseFirstValueOrZero ¶ added in v1.1.24
func ParseOrZero ¶ added in v1.1.24
ParseOrZero returns a parsed time.Time or the RFC-3339 zero time.
func ParseSlice ¶ added in v1.1.24
func ParseTimeSQLTimestampUsingOffset ¶ added in v1.1.24
ParseTimeSQLTimestampUsingOffset converts a SQL timestamp without timezone adding in a manual integer timezone.
func ParseTimeUsingOffset ¶ added in v1.1.24
func RangeStringDateToTime ¶ added in v1.1.30
func ReferenceTime ¶
ReferenceTime Return the standard Golang reference time (2006-01-02T15:04:05.999999999Z07:00)
func SecondToDurationpb ¶ added in v1.1.20
func SecondToDurationpb(seconds *float64) *durationpb.Duration
func SecondsDifferenceDays ¶
SecondsDifferenceDays 两天之间相差了多少天
func SecondsToTimestamp ¶ added in v1.1.30
func SecondsToTimestamp(seconds *int64) *timestamppb.Timestamp
SecondsToTimestamp 将秒转换为 timestamppb.Timestamp
func StringDifferenceDays ¶
StringDifferenceDays 两天之间相差了多少天
func StringToDurationpb ¶ added in v1.1.23
func StringToDurationpb(in *string) *durationpb.Duration
func StringToTimestamppb ¶ added in v1.1.37
func StringToTimestamppb(str *string) *timestamppb.Timestamp
StringToTimestamppb 字符串 -> timestamppb.Timestamp
func StringToUnixMilliInt64Ptr ¶
StringToUnixMilliInt64Ptr 字符串 -> 毫秒时间戳
func TimeDifferenceDays ¶
TimeDifferenceDays 两天之间相差了多少天
func TimeMinRFC3339 ¶ added in v1.1.24
func TimeToTimestamppb ¶ added in v1.1.10
func TimeToTimestamppb(tm *time.Time) *timestamppb.Timestamp
TimeToTimestamppb time.Time -> timestamppb.Timestamp
func TimeToUnixMilliInt64Ptr ¶ added in v1.1.22
TimeToUnixMilliInt64Ptr 时间 -> 毫秒时间戳
func TimeToUnixSecondInt64Ptr ¶ added in v1.1.22
TimeToUnixSecondInt64Ptr 时间 -> 秒时间戳
func TimeZeroRFC3339 ¶ added in v1.1.24
func TimeZeroUnix ¶ added in v1.1.24
func TimestampToMicroseconds ¶ added in v1.1.30
func TimestampToMicroseconds(ts *timestamppb.Timestamp) int64
func TimestampToMilliseconds ¶ added in v1.1.30
func TimestampToMilliseconds(ts *timestamppb.Timestamp) int64
func TimestampToNanoseconds ¶ added in v1.1.30
func TimestampToNanoseconds(ts *timestamppb.Timestamp) int64
TimestampToNanoseconds 将 timestamppb.Timestamp 转换为纳秒
func TimestampToSeconds ¶ added in v1.1.30
func TimestampToSeconds(ts *timestamppb.Timestamp) int64
TimestampToSeconds 将 timestamppb.Timestamp 转换为秒
func TimestamppbToString ¶ added in v1.1.37
func TimestamppbToString(ts *timestamppb.Timestamp) *string
TimestamppbToString timestamppb.Timestamp -> 字符串
func TimestamppbToTime ¶ added in v1.1.10
func TimestamppbToTime(timestamp *timestamppb.Timestamp) *time.Time
TimestamppbToTime timestamppb.Timestamp -> time.Time
func UnixMilliToStringPtr ¶
UnixMilliToStringPtr 毫秒时间戳 -> 字符串
func UnixMilliToTimePtr ¶ added in v1.1.22
UnixMilliToTimePtr 毫秒时间戳 -> 时间
func UnixSecondToTimePtr ¶ added in v1.1.22
UnixSecondToTimePtr 秒时间戳 -> 时间
Types ¶
type ISO8601NoTzMilliTime ¶ added in v1.1.24
func (ISO8601NoTzMilliTime) MarshalJSON ¶ added in v1.1.24
func (t ISO8601NoTzMilliTime) MarshalJSON() ([]byte, error)
func (*ISO8601NoTzMilliTime) UnmarshalJSON ¶ added in v1.1.24
func (t *ISO8601NoTzMilliTime) UnmarshalJSON(buf []byte) error
type RFC3339YMDTime ¶ added in v1.1.24
func (RFC3339YMDTime) MarshalJSON ¶ added in v1.1.24
func (t RFC3339YMDTime) MarshalJSON() ([]byte, error)
func (*RFC3339YMDTime) UnmarshalJSON ¶ added in v1.1.24
func (t *RFC3339YMDTime) UnmarshalJSON(buf []byte) error