Skip to content

golang的time.Time类型的强化类型,针对yyyy-MM-dd HH:mm:ss的字符串场景做了本地化处理

License

Notifications You must be signed in to change notification settings

zaaksam/datetime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Datetime

Go的time.Time的增强类型

How To Use:

dt := datetime.New()
fmt.Println(dt) // yyyy-MM-dd HH:mm:ss

get、set yyyy-MM-dd HH:mm:ss

//get
dtStr := dt.String()

//set
err := dt.SetString("yyyy-MM-dd HH:mm:ss")

get、set time.Time

//get
t := dt.Time()

//set
dt.SetTime(time.Now())

get、set Unix timestamp

//get
u := dt.Unix()

//set
dt.SetUnix(int64(123))

for JSON

type st struct {
    DT Datetime
}
s := &st{}

//Marshal
j,e := json.Marshal(s)
fmt.Println(string(j)) // {"DT": "yyyy-MM-dd HH:mm:ss"}

//Unmarshal
e := json.UnMarshal([]byte(`{"DT": "yyyy-MM-dd HH:mm:ss"}`), s) // it's ok

About

golang的time.Time类型的强化类型,针对yyyy-MM-dd HH:mm:ss的字符串场景做了本地化处理

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages