1## Now 2 3Now is a time toolkit for golang 4 5#### Why the project named `Now`? 6 7```go 8now.BeginningOfDay() 9``` 10`now` is quite readable, aha? 11 12#### But `now` is so common I can't search the project with my favorite search engine 13 14* Star it in github [https://github.com/jinzhu/now](https://github.com/jinzhu/now) 15* Search it with [http://godoc.org](http://godoc.org) 16 17## Install 18 19``` 20go get -u github.com/jinzhu/now 21``` 22 23### Usage 24 25```go 26import "github.com/jinzhu/now" 27 28time.Now() // 2013-11-18 17:51:49.123456789 Mon 29 30now.BeginningOfMinute() // 2013-11-18 17:51:00 Mon 31now.BeginningOfHour() // 2013-11-18 17:00:00 Mon 32now.BeginningOfDay() // 2013-11-18 00:00:00 Mon 33now.BeginningOfWeek() // 2013-11-17 00:00:00 Sun 34now.FirstDayMonday = true // Set Monday as first day, default is Sunday 35now.BeginningOfWeek() // 2013-11-18 00:00:00 Mon 36now.BeginningOfMonth() // 2013-11-01 00:00:00 Fri 37now.BeginningOfQuarter() // 2013-10-01 00:00:00 Tue 38now.BeginningOfYear() // 2013-01-01 00:00:00 Tue 39 40now.EndOfMinute() // 2013-11-18 17:51:59.999999999 Mon 41now.EndOfHour() // 2013-11-18 17:59:59.999999999 Mon 42now.EndOfDay() // 2013-11-18 23:59:59.999999999 Mon 43now.EndOfWeek() // 2013-11-23 23:59:59.999999999 Sat 44now.FirstDayMonday = true // Set Monday as first day, default is Sunday 45now.EndOfWeek() // 2013-11-24 23:59:59.999999999 Sun 46now.EndOfMonth() // 2013-11-30 23:59:59.999999999 Sat 47now.EndOfQuarter() // 2013-12-31 23:59:59.999999999 Tue 48now.EndOfYear() // 2013-12-31 23:59:59.999999999 Tue 49 50 51// Use another time 52t := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.Now().Location()) 53now.New(t).EndOfMonth() // 2013-02-28 23:59:59.999999999 Thu 54 55 56// Don't want be bothered with the First Day setting, Use Monday, Sunday 57now.Monday() // 2013-11-18 00:00:00 Mon 58now.Sunday() // 2013-11-24 00:00:00 Sun (Next Sunday) 59now.EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun (End of next Sunday) 60 61t := time.Date(2013, 11, 24, 17, 51, 49, 123456789, time.Now().Location()) // 2013-11-24 17:51:49.123456789 Sun 62now.New(t).Monday() // 2013-11-18 00:00:00 Sun (Last Monday if today is Sunday) 63now.New(t).Sunday() // 2013-11-24 00:00:00 Sun (Beginning Of Today if today is Sunday) 64now.New(t).EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun (End of Today if today is Sunday) 65``` 66 67#### Parse String 68 69```go 70time.Now() // 2013-11-18 17:51:49.123456789 Mon 71 72// Parse(string) (time.Time, error) 73t, err := now.Parse("12:20") // 2013-11-18 12:20:00, nil 74t, err := now.Parse("1999-12-12 12:20") // 1999-12-12 12:20:00, nil 75t, err := now.Parse("99:99") // 2013-11-18 12:20:00, Can't parse string as time: 99:99 76 77// MustParse(string) time.Time 78now.MustParse("2013-01-13") // 2013-01-13 00:00:00 79now.MustParse("02-17") // 2013-02-17 00:00:00 80now.MustParse("2-17") // 2013-02-17 00:00:00 81now.MustParse("8") // 2013-11-18 08:00:00 82now.MustParse("2002-10-12 22:14") // 2002-10-12 22:14:00 83now.MustParse("99:99") // panic: Can't parse string as time: 99:99 84``` 85 86Extend `now` to support more formats is quite easy, just update `TimeFormats` variable with `time.Format` like time layout 87 88```go 89now.TimeFormats = append(now.TimeFormats, "02 Jan 2006 15:04") 90``` 91 92Please send me pull requests if you want a format to be supported officially 93 94# Author 95 96**jinzhu** 97 98* <http://github.com/jinzhu> 99* <wosmvp@gmail.com> 100* <http://twitter.com/zhangjinzhu> 101 102## License 103 104Released under the [MIT License](http://www.opensource.org/licenses/MIT). 105