timex is a usefull golang time toolkit
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
LICENCE
README.md
json_time.go
json_time_test.go
timex.go
timex_test.go

README.md

Timex

Build Status

Timex is a golang time toolkit package based on time package

Install

go get -u -v github.com/DarthPestilane/timex

Usage

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`` functions

Format 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:59

Timezone convertion

t := timex.NowInTz("UTC") // -> UTC 2018-07-23 15:09:45
t.StartOfDay().MustTz("PRC").DatetimeStr() // 2018-07-23 08:00:00

Raw time.Time operation

tt := t.Raw // time.Time
fmt.Println("Current year is", tt.Year)

Contribute

Feel free