Now is a time toolkit for golang
Now is a time toolkit for golang
go get -u github.com/jinzhu/now
Calculating time based on current time
…
Calculating time based on another time
t := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.Now().Location())
now.With(t).EndOfMonth() // 2013-02-28 23:59:59.999999999 Thu
Calculating time based on configuration
location, err := time.LoadLocation("Asia/Shanghai")
myConfig := &now.Config{
WeekStartDay: time.Monday,
TimeLocation: location,
TimeFormats: []string{"2006-01-02 15:04:05"},
}
t := time.Date(2013, 11, 18, 17, 51, 49, 123456789, time.Now().Location()) // // 2013-11-18 17:51:49.123456789 Mon
myConfig.With(t).BeginningOfWeek() // 2013-11-18 00:00:00 Mon
myConfig.Parse("2002-10-12 22:14:01") // 2002-10-12 22:14:01
myConfig.Parse("2002-10-12 22:14") // returns error 'can't parse string as time: 2002-10-12 22:14'
Don't be bothered with the WeekStartDay setting, you can use Monday, Sunday
…
…
Extend now to support more formats is quite easy, just update now.TimeFormats with other time layouts, e.g:
now.TimeFormats = append(now.TimeFormats, "02 Jan 2006 15:04")
Please send me pull requests if you want a format to be supported officially
You can help to make the project better, check out http://gorm.io/contribute.html for things you can do.
jinzhu
Released under the MIT License.
No open issues yet, or sync has not completed.