更新部分格式化逻辑
This commit is contained in:
parent
ac0d81e47c
commit
9d8c708852
37
time.go
37
time.go
@ -19,7 +19,8 @@ import (
|
||||
// Date : 18:28 2023/8/9
|
||||
func Time(inputTime time.Time) *OwnTime {
|
||||
return &OwnTime{
|
||||
inputTime: inputTime,
|
||||
inputTime,
|
||||
"2006-01-02 15:04:05", // 标准的时间格式
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +30,8 @@ func Time(inputTime time.Time) *OwnTime {
|
||||
//
|
||||
// Date : 18:23 2023/8/9
|
||||
type OwnTime struct {
|
||||
inputTime time.Time
|
||||
time.Time
|
||||
standTimeFormat string
|
||||
}
|
||||
|
||||
// GetCurrentFormatTime 获取当前时间的格式化时间(秒)
|
||||
@ -38,10 +40,7 @@ type OwnTime struct {
|
||||
//
|
||||
// Date : 1:34 上午 2021/10/7
|
||||
func (t *OwnTime) GetCurrentFormatTime(layout ...string) string {
|
||||
if len(layout) == 0 {
|
||||
layout = []string{"2006-01-02 15:04:05"}
|
||||
}
|
||||
return time.Now().In(time.Local).Format(layout[0])
|
||||
return time.Now().In(time.Local).Format(t.getTimeFormat(t.standTimeFormat, layout...))
|
||||
}
|
||||
|
||||
// FormatUnixNano 格式化纳秒时间戳
|
||||
@ -49,12 +48,9 @@ func (t *OwnTime) GetCurrentFormatTime(layout ...string) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:54 2022/7/14
|
||||
func (t *OwnTime) FormatUnixNano(timestamp int64, layout ...string) string {
|
||||
if len(layout) == 0 {
|
||||
layout = []string{"2006-01-02 15:04:05.000"}
|
||||
}
|
||||
nano := timestamp % 1e6
|
||||
milli := timestamp / 1e6
|
||||
func (t *OwnTime) FormatUnixNano(layout ...string) string {
|
||||
nano := t.UnixNano() % 1e6
|
||||
milli := t.UnixNano() / 1e6
|
||||
return t.FormatUnixMilli(milli, layout...) + fmt.Sprintf(" %v", nano)
|
||||
}
|
||||
|
||||
@ -64,10 +60,7 @@ func (t *OwnTime) FormatUnixNano(timestamp int64, layout ...string) string {
|
||||
//
|
||||
// Date : 11:55 2022/7/14
|
||||
func (t *OwnTime) FormatUnixMilli(timestamp int64, layout ...string) string {
|
||||
if len(layout) == 0 {
|
||||
layout = []string{"2006-01-02 15:04:05.000"}
|
||||
}
|
||||
return time.UnixMilli(timestamp).In(time.Local).Format(layout[0])
|
||||
return time.UnixMilli(timestamp).In(time.Local).Format(t.getTimeFormat(t.standTimeFormat, layout...))
|
||||
}
|
||||
|
||||
// FormatUnixSec ...
|
||||
@ -100,3 +93,15 @@ func (t *OwnTime) ParseISO8601Time(parseTime string) string {
|
||||
|
||||
return formatTime.In(time.Local).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// getTimeFormat 获取时间格式
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:37 2023/8/9
|
||||
func (t *OwnTime) getTimeFormat(defaultFormat string, layout ...string) string {
|
||||
if len(layout) > 0 && len(layout[0]) > 0 {
|
||||
return layout[0]
|
||||
}
|
||||
return defaultFormat
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user