Timex
Timex is a golang time toolkit package based on time package
Install
go get -u -v github.com/DarthPestilane/timexUsage
New Timex object
import "github.com/DarthPestilane/timex"
// current time
t := timex.Now() // -> UTC 2018-07-23 15:09:45
t := timex.NowInTz("PRC") // -> CST 2018-07-23 23:09:45
// based on `time.Time`
t := timex.New(time.Now())
// parse string
t := timex.FuzzyParse("2018-07-23 15:45:24")
// also provides `Parse` `MustParse` `ParseInTz` `MustParseInTz`` functionsFormat to string
t.DatetimeStr() // 2018-07-23 14:59:58
t.DateStr() // 2018-07-23 00:00:00
// for other formats
t.Format(layout)StartOf/EndOf functions
t.StartOfDay().DatetimeStr() // 2018-07-23 00:00:00
t.EndOfDay().DatetimeStr() // 2018-07-23 23:59:59
t.StartOfMonth().DatetimeStr() // 2018-07-01 00:00:00
t.EndOfMonth().DatetimeStr() // 2018-07-31 23:59:59
t.StartOfYear().DatetimeStr() // 2018-01-01 00:00:00
t.EndOfYear().DatetimeStr() // 2018-12-31 23:59:59Timezone convertion
t := timex.NowInTz("UTC") // -> UTC 2018-07-23 15:09:45
t.StartOfDay().MustTz("PRC").DatetimeStr() // 2018-07-23 08:00:00Raw time.Time operation
tt := t.Raw // time.Time
fmt.Println("Current year is", tt.Year)Contribute
Feel free