base

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MulanPSL-2.0 Imports: 9 Imported by: 5

README

base

介绍
  • 基本数据类型常用方法封装

Documentation

Index

Constants

View Source
const (
	DayInt                       = 24 * 3600
	DayDur                       = 24 * time.Hour
	StartTimeSuffix              = " 00:00:00"
	EndTimeSuffix                = " 23:59:59"
	GetDateBetweenForDate  int32 = 1 // 按日处理
	GetDateBetweenForMonth int32 = 2 // 按月处理
	GetDateBetweenForYear  int32 = 3 // 按年处理
)
View Source
const (
	// 时间格式
	YearFmt int8 = 1 << iota
	MonthFmt
	DayFmt
	HourFmt
	MinFmt
	SecFmt

	DateFmtFlag     = YearFmt | MonthFmt | DayFmt
	DateTimeFmtFlag = DateFmtFlag | HourFmt | MinFmt | SecFmt
)
View Source
const (
	KCRandKindNum   = 0 // 纯数字
	KCRandKindLower = 1 // 小写字母
	KCRandKindUpper = 2 // 大写字母
	KCRandKindAll   = 3 // 数字、大小写字母
)

用于获取随机字符串

Variables

View Source
var (
	DateFmt     = GetTimeFmt(DateFmtFlag)     // 2006-01-02
	DatetimeFmt = GetTimeFmt(DateTimeFmtFlag) // 2006-01-02 15:04:05
)

Functions

func AddDate

func AddDate(date string, add time.Duration, format ...string) time.Time

AddDate 增加时间

func AddDateForInt

func AddDateForInt(date string, years, months, days int, format ...string) time.Time

AddDateForInt 增加时间

func Datetime2TimeObj

func Datetime2TimeObj(target string, format ...string) time.Time

Datetime2TimeObj

func Datetime2Timestamp

func Datetime2Timestamp(date string, format ...string) int64

Datetime2Timestamp 将时间字符串转为时间戳

func DatetimeBetween

func DatetimeBetween(target, startDatetime, endDatetime string) bool

DatetimeBetween 判断目标时间是否在开始时间和结束时间之间

func DatetimeIsExpire

func DatetimeIsExpire(date string, expire ...time.Duration) bool

DatetimeIsExpire 判断输入时间是否过期

func DistinctIds

func DistinctIds(ids []string) []string

DistinctIds 去重

func DistinctIdsStr

func DistinctIdsStr(s string, split string) string

DistinctIdsStr 将输入拼接 id 参数按照指定字符进行去重, 如: DistinctIdsStr("12345,123,20,123,20,15", ",") => 12345,123,20,15

func DistinctInt32Ids

func DistinctInt32Ids(ids []int32) (res []int32)

DistinctInt32Ids 去重

func FormatBusinessDate

func FormatBusinessDate(date string) (finalStr string)

FormatBusinessDate 将输入的时间转为业务需要时间, 规则如下: 1. 1分钟内发布的: 刚刚 2. 1小时内发布的: X分钟前 3. 超过1小时, 仍在当天: xx:xx 4. 跨天,但少于24小时: 昨天 xx:xx 5. 跨天, 超过24小时: xxxx-xx-xx xx:xx

func GetAgeForBirthday

func GetAgeForBirthday(birthday string, format ...string) (age int)

GetAgeForBirthday 根据出生日期获取年龄

func GetDateBetween

func GetDateBetween(startDate, endDate string, args ...int32) []string

GetDateBetween 获取开始时间和结束时间中的日期 args[0] 为操作类型, 默认为 GetDateBetweenForDate args[1] 为了防止死循环设置的最大循环次数, 默认 365(1年)

func GetInputStr2ShortStr

func GetInputStr2ShortStr(input string, size ...int) string

GetInputStr2ShortStr size 建议不要传入, 这样会提高重复率

func GetJson2Dump added in v1.2.6

func GetJson2Dump(data interface{}) string

GetJson2Dump 获取待打印的内容

func GetJsonPrintStr

func GetJsonPrintStr(v interface{}) string

GetJsonPrintStr 获取打印 json 串

func GetPageSliceIndex

func GetPageSliceIndex(page, size int32, l int) (startIndex, endIndex int32)

GetPageSliceIndex 根据page, size对切片进行分页, l 为目标切片的长度

func GetPlaceholderStrForNum

func GetPlaceholderStrForNum(size int, num int64, placeholder ...byte) string

GetPlaceholderStrForNum 获取指定位数占位符的字符串

func GetShortStrForRand

func GetShortStrForRand(size int, kind ...int) string

GetShortStrForRand 随机字符串, 默认按照: 数字、大小写字母进行处理

func GetTargeMonthDur

func GetTargeMonthDur(target time.Time) (startDatetime, endDatetime string)

GetCurMonthDur 获取指定月的开始和结束时间

func GetTargetDateDur

func GetTargetDateDur(target time.Time) (startDatetime, endDatetime string)

GetAddDateDur 获取指定时间的当天开始时间和结束时间

func GetTimeFmt added in v1.2.6

func GetTimeFmt(fmtType int8, splits ...string) (res string)

GetTimeFmt 获取时间格式化 splits 为分隔符 splits[0] 为 [年月日] 的分割符, 默认为 "-" splits[1] 为 [年月日] 和 [时分秒] 的分割符, 默认为 " " splits[2] 为 [时分秒] 的分割符, 默认为 ":"

func GetWeekInfoForTime

func GetWeekInfoForTime(dateFormat string, t ...time.Time) *weekInfo

GetWeekInfoForTime 根据输入的 time 来获取本周的日期和星期几, 如果没有输入默认按当前时间处理

func InInt32Array

func InInt32Array(target int32, in ...int32) bool

InInt32Array 在 int32 数组

func InString added in v1.1.2

func InString(target string, ins ...string) bool

InString 目标是否在这些内容中

func InUint8Array

func InUint8Array(target uint8, in ...uint8) bool

InUint8Array 在 uint8 数组

func IsExported

func IsExported(fieldName string) bool

IsExported 是可导出

func MurmurHash2Uint64

func MurmurHash2Uint64(data []byte) (hash uint64)

MurmurHash2Uint64 通过 Murmur 获取 hash uint64 的哈希值

func PriceNum2Str

func PriceNum2Str(value int32) string

PriceNum2Str 价格处理, 将价格: 元=>分

func PriceStr2Str

func PriceStr2Str(value string) (ans string)

PriceStr2Str 价格处理, 将价格: 元=>分

func RemoveTypePtr

func RemoveTypePtr(t reflect.Type) reflect.Type

RemoveTypePtr 移除多指针

func RemoveValuePtr

func RemoveValuePtr(t reflect.Value) reflect.Value

RemoveValuePtr 移除多指针

func Second2Hour

func Second2Hour(s int) (hour, min, sec int)

Second2Hour 秒转分

func SubDate

func SubDate(date, sub string, format ...string) time.Duration

SubDate 获取两个时间的差值

func SubNow2Year

func SubNow2Year(year string) string

SubNow2Year 目标年与现在的差

func Timestamp2Datetime

func Timestamp2Datetime(timestamp int64, format ...string) string

Timestamp2Datetime 将时间戳转为时间字符串

func ToString

func ToString(src interface{}, jsonEscapeHTML ...bool) string

ToString 将内容转为 string, 性能是优于 fmt.Sprintf

Types

This section is empty.

Jump to

Keyboard shortcuts

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