支持时间的包装类型 #1
22
time.go
22
time.go
@ -12,24 +12,24 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Time ...
|
||||
// OwnTime ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:28 2023/8/9
|
||||
func Time(inputTime time.Time) *OwnTime {
|
||||
return &OwnTime{
|
||||
func OwnTime(inputTime time.Time) *Time {
|
||||
return &Time{
|
||||
inputTime,
|
||||
"2006-01-02 15:04:05", // 标准的时间格式
|
||||
}
|
||||
}
|
||||
|
||||
// OwnTime 时间类型
|
||||
// Time 时间类型
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:23 2023/8/9
|
||||
type OwnTime struct {
|
||||
type Time struct {
|
||||
time.Time
|
||||
standTimeFormat string
|
||||
}
|
||||
@ -39,7 +39,7 @@ type OwnTime struct {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 1:34 上午 2021/10/7
|
||||
func (t *OwnTime) GetCurrentFormatTime(layout ...string) string {
|
||||
func (t *Time) GetCurrentFormatTime(layout ...string) string {
|
||||
return time.Now().In(time.Local).Format(t.getTimeFormat(t.standTimeFormat, layout...))
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ func (t *OwnTime) GetCurrentFormatTime(layout ...string) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:54 2022/7/14
|
||||
func (t *OwnTime) FormatUnixNano(layout ...string) string {
|
||||
func (t *Time) FormatUnixNano(layout ...string) string {
|
||||
nano := t.UnixNano() % 1e6
|
||||
milli := t.UnixNano() / 1e6
|
||||
return t.FormatUnixMilli(milli, layout...) + fmt.Sprintf(" %v", nano)
|
||||
@ -59,7 +59,7 @@ func (t *OwnTime) FormatUnixNano(layout ...string) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:55 2022/7/14
|
||||
func (t *OwnTime) FormatUnixMilli(timestamp int64, layout ...string) string {
|
||||
func (t *Time) FormatUnixMilli(timestamp int64, layout ...string) string {
|
||||
return time.UnixMilli(timestamp).In(time.Local).Format(t.getTimeFormat(t.standTimeFormat, layout...))
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (t *OwnTime) FormatUnixMilli(timestamp int64, layout ...string) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:06 2022/7/14
|
||||
func (t *OwnTime) FormatUnixSec(timestamp int64, layout ...string) string {
|
||||
func (t *Time) FormatUnixSec(timestamp int64, layout ...string) string {
|
||||
if len(layout) == 0 {
|
||||
layout = []string{"2006-01-02 15:04:05"}
|
||||
}
|
||||
@ -80,7 +80,7 @@ func (t *OwnTime) FormatUnixSec(timestamp int64, layout ...string) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 13:48 2022/7/14
|
||||
func (t *OwnTime) ParseISO8601Time(parseTime string) string {
|
||||
func (t *Time) ParseISO8601Time(parseTime string) string {
|
||||
var (
|
||||
timeLayout = "2006-01-02T15:04:05+08:00"
|
||||
formatTime time.Time
|
||||
@ -99,7 +99,7 @@ func (t *OwnTime) ParseISO8601Time(parseTime string) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:37 2023/8/9
|
||||
func (t *OwnTime) getTimeFormat(defaultFormat string, layout ...string) string {
|
||||
func (t *Time) getTimeFormat(defaultFormat string, layout ...string) string {
|
||||
if len(layout) > 0 && len(layout[0]) > 0 {
|
||||
return layout[0]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user