diff --git a/time.go b/time.go index 004d9db..69741bc 100644 --- a/time.go +++ b/time.go @@ -7,7 +7,10 @@ // Date : 2021-10-07 1:33 上午 package util -import "time" +import ( + "fmt" + "time" +) // ownTime ... // @@ -25,3 +28,52 @@ type ownTime struct { func (ot *ownTime) GetCurrentFormatTime() string { return time.Now().Format("2006-01-02 15:04:05") } + +// FormatUnixNano 格式化纳秒时间戳 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:54 2022/7/14 +func (ot *ownTime) FormatUnixNano(timestamp int64) string { + nano := timestamp % 1e6 + milli := timestamp / 1e6 + return ot.FormatUnixMilli(milli) + fmt.Sprintf(" %v", nano) +} + +// FormatUnixMilli 格式化毫秒时间戳 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:55 2022/7/14 +func (ot *ownTime) FormatUnixMilli(timestamp int64) string { + time.Now().UnixMilli() + return time.UnixMilli(timestamp).Format("2006-01-02 15:04:05.000") +} + +// FormatUnixSec ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 12:06 2022/7/14 +func (ot *ownTime) FormatUnixSec(timestamp int64) string { + return time.UnixMilli(timestamp).Format("2006-01-02 15:04:05") +} + +// ParseISO8601Time 解析 2006-01-02T15:04:05+08:00 格式时间 -> 2006-01-02 15:04:05 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 13:48 2022/7/14 +func (ot *ownTime) ParseISO8601Time(parseTime string) string { + var ( + timeLayout = "2006-01-02T15:04:05+08:00" + formatTime time.Time + err error + ) + + if formatTime, err = time.Parse(timeLayout, parseTime); nil != err { + return "" + } + + return formatTime.Format("2006-01-02 15:04:05") +}