增加各种规则的时间格式化
This commit is contained in:
parent
ad77044f1e
commit
3cfcad0c65
54
time.go
54
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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user