utils

package
v0.0.0-...-0569e1c Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0 Imports: 14 Imported by: 12

Documentation

Index

Constants

View Source
const (
	TIME_FORMAT_WITH_T   = "2006-01-02T15:04:05"
	TIME_FORMAT1         = "02-01-2006 15:04:00" // "dd-MM-yyyy HH:mm:ss" 秒数为 00
	TIME_FORMAT2         = "02-01-2006 15:04:05" // "dd-MM-yyyy HH:mm:ss"
	TIME_FORMAT3         = "01/02/2006 15:04:05" // MM/DD/YYYY HH:MM:SS
	TIME_FORMAT4         = "2006-01-02 15:04:00" // 秒数为 00
	TIME_FORMAT5         = "2006/01/02 15:04:05" // YYYY/MM/DD HH:mm:ss
	TIME_FORMAT_COMPACT1 = "060102150405"
	DATE_FORMAT1         = "2006/01/02"
	DATE_FORMAT_COMPACT1 = "20060102 15:04:05"
	MONTH_FORMAT1        = "2006-1"

	TIME_FORMAT_WITH_MS         = "2006-01-02 15:04:05.000"
	TIME_FORMAT                 = "2006-01-02 15:04:05"
	TIME_FORMAT_WO_SEC_COMPACT  = "200601021504"
	TIME_FORMAT_COMPACT         = "20060102150405"
	TIME_FORMAT_WITH_MS_COMPACT = "20060102150405000"
	DATE_FORMAT                 = "2006-01-02"
	DATE_FORMAT_COMPACT         = "20060102"
	MONTH_FORMAT                = "2006-01"
)
View Source
const (
	TIME_LOC_ASIA_SHANGHAI    = "Asia/Shanghai"    //+0800
	TIME_LOC_ASIA_TAIPEI      = "Asia/Taipei"      //+0800
	TIME_LOC_AMERICA_NEW_YORK = "America/New_York" //-0400(夏) -0500(冬)
	TIME_LOC_UTC              = "UTC"
)

Variables

View Source
var Rander = rand.New(rand.NewSource(time.Now().UnixNano())) // 线程不安全

Functions

func ASSERT

func ASSERT(exp bool, info ...string)

func CalcTimeSecond

func CalcTimeSecond(stime string) (*time.Time, int64, error)

func CatchException

func CatchException()

func CatchExceptionWithName

func CatchExceptionWithName(name string)

func CatchPanic

func CatchPanic()

func DateStr

func DateStr(t time.Time) string

func DecodeFromJson

func DecodeFromJson(jsonstr string, st interface{}) error

func EncodeToJson

func EncodeToJson(st interface{}) string

func FormatJsonStr

func FormatJsonStr(instr string) string

func FormatStruct

func FormatStruct(inst interface{}) string

func GetOneMonthRangeDate

func GetOneMonthRangeDate(d time.Time) (time.Time, time.Time, error)

get the first date and the last date of a month

func GetOneMonthRangeDateStr

func GetOneMonthRangeDateStr(d time.Time) (string, string, error)

get the first date and the last date of a month

func GetTimeByChangeTimeZone

func GetTimeByChangeTimeZone(layout string, timeStr string, srcTimeZone string, destTimeZone string) (time.Time, error)

change time zone

func GetTimeFromFormat

func GetTimeFromFormat(layout string, timeStr string, location string) (time.Time, error)

string time to time.Time in location

func GetTimeFromString

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

func GetTimeOfMs

func GetTimeOfMs() int64

Millisecond timestrap

func GetTimeOfNs

func GetTimeOfNs() int64

Nanosecond timestrap

func GetTimeOfS

func GetTimeOfS() int64

Second timestrap

func GetTimeStrFromFormat

func GetTimeStrFromFormat(layout string, timeClass time.Time, location string) string

time.Time to string time in location

func IsNullTime

func IsNullTime(t time.Time) bool

func IsValidDate

func IsValidDate(d string) bool

func IsValidDateTime

func IsValidDateTime(dt string) bool

func IsValidTime

func IsValidTime(t string) bool

func MakeEternalTime

func MakeEternalTime() time.Time

func NowDate

func NowDate() string

func NowDateStr

func NowDateStr() string

func NowMS

func NowMS() string

func NowStr

func NowStr() string

func NowWithMS

func NowWithMS() string

func RandNum

func RandNum(min, max int) int

包含min, max

func SerializeToJson

func SerializeToJson(st interface{}) string

func Shuffle

func Shuffle(src []string) []string

* Returns a random shuffling of the array.

func Time2Date

func Time2Date(t time.Time) time.Time

func TimeStr

func TimeStr(t time.Time) string

func UseMaxCpu

func UseMaxCpu()

Types

This section is empty.

Jump to

Keyboard shortcuts

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