util

package
v0.0.0-...-110d06e Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	TT1 TimeTemplate = "2006-01-02 15:04:05"
	TT2              = "2006/01/02 15:04:05"
	TT3              = "2006-01-02"
	TT4              = "20060102"
	TT5              = "15:04:05"
)
View Source
const CNM = `` /* 306-byte string literal not displayed */
View Source
const DEEPLINK = `` /* 152-byte string literal not displayed */
View Source
const EMTF = `` /* 1003-byte string literal not displayed */
View Source
const HOLLSON = `` /* 301-byte string literal not displayed */
View Source
const SYBS = `
           __     
  _____ __/ /  ___
 (_-/ // / _ \(_-<
/___\_, /_.__/___/
   /___/          `

Variables

This section is empty.

Functions

func DateShrink

func DateShrink(tm time.Time) time.Time

DateShrink 只包含年月日的时间(即:抹掉时分秒)

func Decimal

func Decimal(value float64) float64

保留两位

func GetGmtimeStr

func GetGmtimeStr() string

func GetLocaltimeStr

func GetLocaltimeStr() string

func GetTmShortStr

func GetTmShortStr(tm time.Time, format string) string

func GetTmStr

func GetTmStr(tm time.Time, format string) string

func GetUnixTimeShortStr

func GetUnixTimeShortStr(ut int64, format string) string

func GetUnixTimeStr

func GetUnixTimeStr(ut int64, format string) string

func GoStdRubyDate

func GoStdRubyDate() string

func GoStdTime

func GoStdTime() string

func GoStdUnixDate

func GoStdUnixDate() string

func Greatest

func Greatest(arr []time.Time) time.Time

func RandIntn

func RandIntn(n int) int

func ShiftZone

func ShiftZone(toLoc *time.Location, from ...time.Time) time.Time

ShiftZone 时区转换/换置(即:将from时间转换为toLoc时区的时间)

Example
// 将当前时间转换为纽约时间
loc, _ := time.LoadLocation("America/New_York")
_newYorkTime := ShiftZone(loc, time.Now())
_newYorkTime = ShiftZone(loc) // 默认即为Nows
fmt.Println(_newYorkTime)

// out: 2006-01-02 13:04:05.868597 -0500 EST
Output:

func StrToTime

func StrToTime(timeStr string, template TimeTemplate) (time.Time, error)

func ToMonday

func ToMonday(tar ...time.Time) time.Time

ToMonday 转到以tar为坐标的周一时间点,tar默认为当前时间

func Zone

func Zone(loc *time.Location) (name string, zone int)

Zone 获取时区标识与时区值

常用时区名称:
  Asia/Shanghai:       上海
  Asia/Taipei:         台北
  Asia/Seoul:          首尔
  Asia/Tokyo:          东京
  Asia/Singapore:      新加坡
  Asia/Jerusalem:      耶路撒冷
  Asia/Kolkata:        加尔各答(印度)
  America/Los_Angeles: 洛杉矶
  America/New_York:    纽约
  Europe/Dublin:       都柏林
  Europe/London:       伦敦
更多参考:(🔥源码才是最好的参考文档)
  cat /private/etc/localtime
  cat etc/localtime
  ls usr/share/zoneinfo
  https://www.zeitverschiebung.net/cn/city/2643743
Example
loc, _ := time.LoadLocation("Asia/Shanghai")
name, zone := Zone(loc)
fmt.Println(name, zone)

// out: CST +8
Output:

Types

type TimeSlice

type TimeSlice []time.Time

func (TimeSlice) Len

func (s TimeSlice) Len() int

func (TimeSlice) Less

func (s TimeSlice) Less(i, j int) bool

func (TimeSlice) Swap

func (s TimeSlice) Swap(i, j int)

type TimeTemplate

type TimeTemplate string

Jump to

Keyboard shortcuts

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