Documentation ¶
Overview ¶
Package now is a time toolkit for golang.
More details README here: https://github.com/jinzhu/now
import "github.com/jinzhu/now" now.BeginningOfMinute() // 2013-11-18 17:51:00 Mon now.BeginningOfDay() // 2013-11-18 00:00:00 Mon now.EndOfDay() // 2013-11-18 23:59:59.999999999 Mon
Example ¶
time.Now() // 2013-11-18 17:51:49.123456789 Mon BeginningOfMinute() // 2013-11-18 17:51:00 Mon BeginningOfHour() // 2013-11-18 17:00:00 Mon BeginningOfDay() // 2013-11-18 00:00:00 Mon BeginningOfWeek() // 2013-11-17 00:00:00 Sun WeekStartDay = time.Monday // Set Monday as first day BeginningOfWeek() // 2013-11-18 00:00:00 Mon BeginningOfMonth() // 2013-11-01 00:00:00 Fri BeginningOfQuarter() // 2013-10-01 00:00:00 Tue BeginningOfYear() // 2013-01-01 00:00:00 Tue EndOfMinute() // 2013-11-18 17:51:59.999999999 Mon EndOfHour() // 2013-11-18 17:59:59.999999999 Mon EndOfDay() // 2013-11-18 23:59:59.999999999 Mon EndOfWeek() // 2013-11-23 23:59:59.999999999 Sat WeekStartDay = time.Monday // Set Monday as first day EndOfWeek() // 2013-11-24 23:59:59.999999999 Sun EndOfMonth() // 2013-11-30 23:59:59.999999999 Sat EndOfQuarter() // 2013-12-31 23:59:59.999999999 Tue EndOfYear() // 2013-12-31 23:59:59.999999999 Tue // Use another time t := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.UTC) With(t).EndOfMonth() // 2013-02-28 23:59:59.999999999 Thu Monday() // 2013-11-18 00:00:00 Mon Monday("17:44") // 2013-11-18 17:44:00 Mon Sunday() // 2013-11-24 00:00:00 Sun Sunday("17:44") // 2013-11-24 17:44:00 Sun EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun
Output:
Index ¶
- Variables
- func BeginningOfDay() time.Time
- func BeginningOfHour() time.Time
- func BeginningOfMinute() time.Time
- func BeginningOfMonth() time.Time
- func BeginningOfQuarter() time.Time
- func BeginningOfWeek() time.Time
- func BeginningOfYear() time.Time
- func Between(time1, time2 string) bool
- func EndOfDay() time.Time
- func EndOfHour() time.Time
- func EndOfMinute() time.Time
- func EndOfMonth() time.Time
- func EndOfQuarter() time.Time
- func EndOfSunday() time.Time
- func EndOfWeek() time.Time
- func EndOfYear() time.Time
- func Monday(strs ...string) time.Time
- func MustParse(strs ...string) time.Time
- func MustParseInLocation(loc *time.Location, strs ...string) time.Time
- func Parse(strs ...string) (time.Time, error)
- func ParseInLocation(loc *time.Location, strs ...string) (time.Time, error)
- func Quarter() uint
- func Sunday(strs ...string) time.Time
- type Config
- type Now
- func (now *Now) BeginningOfDay() time.Time
- func (now *Now) BeginningOfHalf() time.Time
- func (now *Now) BeginningOfHour() time.Time
- func (now *Now) BeginningOfMinute() time.Time
- func (now *Now) BeginningOfMonth() time.Time
- func (now *Now) BeginningOfQuarter() time.Time
- func (now *Now) BeginningOfWeek() time.Time
- func (now *Now) BeginningOfYear() time.Time
- func (now *Now) Between(begin, end string) bool
- func (now *Now) EndOfDay() time.Time
- func (now *Now) EndOfHalf() time.Time
- func (now *Now) EndOfHour() time.Time
- func (now *Now) EndOfMinute() time.Time
- func (now *Now) EndOfMonth() time.Time
- func (now *Now) EndOfQuarter() time.Time
- func (now *Now) EndOfSunday() time.Time
- func (now *Now) EndOfWeek() time.Time
- func (now *Now) EndOfYear() time.Time
- func (now *Now) Monday(strs ...string) time.Time
- func (now *Now) MustParse(strs ...string) (t time.Time)
- func (now *Now) Parse(strs ...string) (t time.Time, err error)
- func (now *Now) Quarter() uint
- func (now *Now) Sunday(strs ...string) time.Time
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var TimeFormats = []string{ "2006", "2006-1", "2006-1-2", "2006-1-2 15", "2006-1-2 15:4", "2006-1-2 15:4:5", "1-2", "15:4:5", "15:4", "15", "15:4:5 Jan 2, 2006 MST", "2006-01-02 15:04:05.999999999 -0700 MST", "2006-01-02T15:04:05Z0700", "2006-01-02T15:04:05Z07", "2006.1.2", "2006.1.2 15:04:05", "2006.01.02", "2006.01.02 15:04:05", "2006.01.02 15:04:05.999999999", "1/2/2006", "1/2/2006 15:4:5", "2006/01/02", "20060102", "2006/01/02 15:04:05", time.ANSIC, time.UnixDate, time.RubyDate, time.RFC822, time.RFC822Z, time.RFC850, time.RFC1123, time.RFC1123Z, time.RFC3339, time.RFC3339Nano, time.Kitchen, time.Stamp, time.StampMilli, time.StampMicro, time.StampNano, }
TimeFormats default time formats will be parsed as
var WeekStartDay = time.Sunday
WeekStartDay set week start day, default is sunday
Functions ¶
func BeginningOfQuarter ¶
BeginningOfQuarter beginning of quarter
func MustParseInLocation ¶
MustParseInLocation must parse string to time in location or will panic
func ParseInLocation ¶
ParseInLocation parse string to time in location
Types ¶
type Config ¶ added in v1.1.0
Config configuration for now package
var DefaultConfig *Config
DefaultConfig default config
type Now ¶
Now now struct
func (*Now) BeginningOfDay ¶
BeginningOfDay beginning of day
func (*Now) BeginningOfHalf ¶ added in v1.0.1
BeginningOfHalf beginning of half year
func (*Now) BeginningOfHour ¶
BeginningOfHour beginning of hour
func (*Now) BeginningOfMinute ¶
BeginningOfMinute beginning of minute
func (*Now) BeginningOfMonth ¶
BeginningOfMonth beginning of month
func (*Now) BeginningOfQuarter ¶
BeginningOfQuarter beginning of quarter
func (*Now) BeginningOfWeek ¶
BeginningOfWeek beginning of week
func (*Now) BeginningOfYear ¶
BeginningOfYear BeginningOfYear beginning of year