From 3cfcad0c6547845c878ad4a7f7f18ad88d2408d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 14 Jul 2022 13:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=84=E7=A7=8D=E8=A7=84?= =?UTF-8?q?=E5=88=99=E7=9A=84=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- time.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) 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") +}