now: github.com/jinzhu/now Index | Examples | Files

package now

import "github.com/jinzhu/now"

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

Code:

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
Sunday()      // 2013-11-24 00:00:00 Sun
EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun

Index

Examples

Package Files

main.go now.go

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:05-07:00",
    "2006.1.2", "2006.1.2 15:04:05", "2006.01.02", "2006.01.02 15:04:05",
    "1/2/2006", "1/2/2006 15:4:5", "2006/01/02", "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

func BeginningOfDay Uses

func BeginningOfDay() time.Time

BeginningOfDay beginning of day

func BeginningOfHour Uses

func BeginningOfHour() time.Time

BeginningOfHour beginning of hour

func BeginningOfMinute Uses

func BeginningOfMinute() time.Time

BeginningOfMinute beginning of minute

func BeginningOfMonth Uses

func BeginningOfMonth() time.Time

BeginningOfMonth beginning of month

func BeginningOfQuarter Uses

func BeginningOfQuarter() time.Time

BeginningOfQuarter beginning of quarter

func BeginningOfWeek Uses

func BeginningOfWeek() time.Time

BeginningOfWeek beginning of week

func BeginningOfYear Uses

func BeginningOfYear() time.Time

BeginningOfYear beginning of year

func Between Uses

func Between(time1, time2 string) bool

Between check now between the begin, end time or not

func EndOfDay Uses

func EndOfDay() time.Time

EndOfDay end of day

func EndOfHour Uses

func EndOfHour() time.Time

EndOfHour end of hour

func EndOfMinute Uses

func EndOfMinute() time.Time

EndOfMinute end of minute

func EndOfMonth Uses

func EndOfMonth() time.Time

EndOfMonth end of month

func EndOfQuarter Uses

func EndOfQuarter() time.Time

EndOfQuarter end of quarter

func EndOfSunday Uses

func EndOfSunday() time.Time

EndOfSunday end of sunday

func EndOfWeek Uses

func EndOfWeek() time.Time

EndOfWeek end of week

func EndOfYear Uses

func EndOfYear() time.Time

EndOfYear end of year

func Monday Uses

func Monday() time.Time

Monday monday

func MustParse Uses

func MustParse(strs ...string) time.Time

MustParse must parse string to time or will panic

func MustParseInLocation Uses

func MustParseInLocation(loc *time.Location, strs ...string) time.Time

MustParseInLocation must parse string to time in location or will panic

func Parse Uses

func Parse(strs ...string) (time.Time, error)

Parse parse string to time

func ParseInLocation Uses

func ParseInLocation(loc *time.Location, strs ...string) (time.Time, error)

ParseInLocation parse string to time in location

func Sunday Uses

func Sunday() time.Time

Sunday sunday

type Config Uses

type Config struct {
    WeekStartDay time.Weekday
    TimeLocation *time.Location
    TimeFormats  []string
}

Config configuration for now package

var DefaultConfig *Config

DefaultConfig default config

func (*Config) MustParse Uses

func (config *Config) MustParse(strs ...string) time.Time

MustParse must parse string to time or will panic

func (*Config) Parse Uses

func (config *Config) Parse(strs ...string) (time.Time, error)

Parse parse string to time based on configuration

func (*Config) With Uses

func (config *Config) With(t time.Time) *Now

New initialize Now based on configuration

type Now Uses

type Now struct {
    time.Time
    *Config
}

Now now struct

func New Uses

func New(t time.Time) *Now

New initialize Now with time

func With Uses

func With(t time.Time) *Now

With initialize Now with time

func (*Now) BeginningOfDay Uses

func (now *Now) BeginningOfDay() time.Time

BeginningOfDay beginning of day

func (*Now) BeginningOfHalf Uses

func (now *Now) BeginningOfHalf() time.Time

BeginningOfHalf beginning of half year

func (*Now) BeginningOfHour Uses

func (now *Now) BeginningOfHour() time.Time

BeginningOfHour beginning of hour

func (*Now) BeginningOfMinute Uses

func (now *Now) BeginningOfMinute() time.Time

BeginningOfMinute beginning of minute

func (*Now) BeginningOfMonth Uses

func (now *Now) BeginningOfMonth() time.Time

BeginningOfMonth beginning of month

func (*Now) BeginningOfQuarter Uses

func (now *Now) BeginningOfQuarter() time.Time

BeginningOfQuarter beginning of quarter

func (*Now) BeginningOfWeek Uses

func (now *Now) BeginningOfWeek() time.Time

BeginningOfWeek beginning of week

func (*Now) BeginningOfYear Uses

func (now *Now) BeginningOfYear() time.Time

BeginningOfYear BeginningOfYear beginning of year

func (*Now) Between Uses

func (now *Now) Between(begin, end string) bool

Between check time between the begin, end time or not

func (*Now) EndOfDay Uses

func (now *Now) EndOfDay() time.Time

EndOfDay end of day

func (*Now) EndOfHalf Uses

func (now *Now) EndOfHalf() time.Time

EndOfHalf end of half year

func (*Now) EndOfHour Uses

func (now *Now) EndOfHour() time.Time

EndOfHour end of hour

func (*Now) EndOfMinute Uses

func (now *Now) EndOfMinute() time.Time

EndOfMinute end of minute

func (*Now) EndOfMonth Uses

func (now *Now) EndOfMonth() time.Time

EndOfMonth end of month

func (*Now) EndOfQuarter Uses

func (now *Now) EndOfQuarter() time.Time

EndOfQuarter end of quarter

func (*Now) EndOfSunday Uses

func (now *Now) EndOfSunday() time.Time

EndOfSunday end of sunday

func (*Now) EndOfWeek Uses

func (now *Now) EndOfWeek() time.Time

EndOfWeek end of week

func (*Now) EndOfYear Uses

func (now *Now) EndOfYear() time.Time

EndOfYear end of year

func (*Now) Monday Uses

func (now *Now) Monday() time.Time

Monday monday

func (*Now) MustParse Uses

func (now *Now) MustParse(strs ...string) (t time.Time)

MustParse must parse string to time or it will panic

func (*Now) Parse Uses

func (now *Now) Parse(strs ...string) (t time.Time, err error)

Parse parse string to time

func (*Now) Sunday Uses

func (now *Now) Sunday() time.Time

Sunday sunday

Package now imports 3 packages (graph) and is imported by 134 packages. Updated 2019-11-26. Refresh now. Tools for package owners.