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
Index ¶
- Constants
- Variables
- func Add(begin time.Time, tm string) (end time.Time)
- 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 FormatTime(tm time.Time, for_str string) string
- func GetDay(time time.Time) int
- func GetDay0(timestamp int64) time.Time
- func GetDayStr(tm time.Time) string
- func GetHour(timestamp int64) int
- func GetHour0(timestamp int64) time.Time
- func GetLastDayCurrentTime(timestamp int64, offset int) time.Time
- func GetLocalTime(tm time.Time) time.Time
- func GetMonDay() int
- func GetMonTS() (int64, error)
- func GetMonth0(timestamp int64) time.Time
- func GetSeveralDaysAgo(day int) (start, end int)
- func GetSysTimeLayout() string
- func GetSystemCurDate() string
- func GetSystemCurTime() int
- func GetTimeStr(tm time.Time) string
- func GetTimeWeek(timestamp int64) int
- func GetToday() (start time.Time, end time.Time)
- func GetUtcDay0(now time.Time, timeZone *time.Location) int64
- func GetUtcTime(tm time.Time) int64
- func GetUtcWeek0(timestamp int64) int64
- func GetWeek0(timestamp int64) time.Time
- func GetYesterday() (start, end int)
- func Monday() time.Time
- func MustParse(strs ...string) time.Time
- func MustParseInLocation(loc *time.Location, strs ...string) time.Time
- func NowTimestamp() int64
- func NowUnix() int64
- func Parse(strs ...string) (time.Time, error)
- func ParseInLocation(loc *time.Location, strs ...string) (time.Time, error)
- func StrToTime(tStr, format string, timeZone *time.Location) time.Time
- func StringTimetoUnix(timestr string) int64
- func Sunday() time.Time
- func TimeFormat(time time.Time, layout string) string
- func TimeFromTimestamp(timestamp int64) time.Time
- func TimeFromUnix(unix int64) time.Time
- func TimeParse(timeStr, layout string) (time.Time, error)
- func TimerByHour(f func())
- func Timestamp(t time.Time) int64
- func TimestampNano() int64
- func UnixToTime(timestamp int64) time.Time
- func WithTimeAsStartOfDay(t time.Time) time.Time
- type Date
- func (d Date) AddDays(n int) Date
- func (d Date) Before(d2 Date) bool
- func (d Date) DaysSince(s Date) (days int)
- func (d Date) In(loc *time.Location) time.Time
- func (d Date) MarshalText() ([]byte, error)
- func (d *Date) Scan(value interface{}) error
- func (d Date) String() string
- func (d Date) ToTime() time.Time
- func (d *Date) UnmarshalText(data []byte) error
- func (d Date) Value() (driver.Value, error)
- type DateTime
- func (dt DateTime) Before(dt2 DateTime) bool
- func (dt DateTime) In(loc *time.Location) time.Time
- func (dt DateTime) MarshalText() ([]byte, error)
- func (dt *DateTime) Scan(value interface{}) error
- func (dt DateTime) String() string
- func (dt *DateTime) UnmarshalText(data []byte) error
- func (dt DateTime) Value() (driver.Value, error)
- 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() 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) Sunday() time.Time
- type Time
- func (t Time) After(tm Time) bool
- func (t Time) MarshalText() ([]byte, error)
- func (t *Time) Scan(value interface{}) error
- func (t Time) String() string
- func (t Time) Subtract(t2 Time) int
- func (t Time) ToDate() time.Time
- func (t *Time) UnmarshalText(data []byte) error
- func (t Time) Value() (driver.Value, error)
Constants ¶
const ( // DefaultFormat = "2006-01-02 15:04:05" Format = "2006-01-02 15:04:05" GoFormat = "2006-01-02 15:04:05.999999999" DateFormat = "2006-01-02" FormattedDateFormat = "Jan 2, 2006" HourMinuteFormat = "15:04" HourFormat = "15" DayDateTimeFormat = "Mon, Aug 2, 2006 3:04 PM" CookieFormat = "Monday, 02-Jan-2006 15:04:05 MST" RFC822Format = "Mon, 02 Jan 06 15:04:05 -0700" RFC1036Format = "Mon, 02 Jan 06 15:04:05 -0700" RFC2822Format = "Mon, 02 Jan 2006 15:04:05 -0700" RFC3339Format = "2006-01-02T15:04:05-07:00" RSSFormat = "Mon, 02 Jan 2006 15:04:05 -0700" WeekStartDay = time.Sunday )
GoTime the different string formats for go dates
Variables ¶
var (
TimeFormats = []string{"1/2/2006", "1/2/2006 15:4:5", "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"}
)
Functions ¶
func BeginningOfQuarter ¶
BeginningOfQuarter beginning of quarter
func GetLastDayCurrentTime ¶
获取offset天的现在时间:注意时区
func GetSeveralDaysAgo ¶
func GetSystemCurTime ¶
func GetSystemCurTime() int
GetSystemCurTime get system current time, nanoseconds value
func GetTimeStr ¶
func GetYesterday ¶
func GetYesterday() (start, end int)
func MustParseInLocation ¶
MustParseInLocation must parse string to time in location or will panic
func ParseInLocation ¶
ParseInLocation parse string to time in location
Types ¶
type Date ¶
type Date struct {
Year int // Year (e.g., 2014).
Month time.Month // Month of the year (January = 1, ...).
Day int // Day of the month, starting at 1.
Valid bool
}
A Date represents a date (year, month, day).
This type does not include location information, and therefore does not describe a unique 24-hour timespan.
func ParseDate ¶
ParseDate parses a string in RFC3339 full-date format and returns the date value it represents.
func (Date) AddDays ¶
AddDays returns the date that is n days in the future. n can also be negative to go into the past.
func (Date) DaysSince ¶
DaysSince returns the signed number of days between the date and s, not including the end day. This is the inverse operation to AddDays.
func (Date) In ¶
In returns the time corresponding to time 00:00:00 of the date in the location.
In is always consistent with time.Date, even when time.Date returns a time on a different day. For example, if loc is America/Indiana/Vincennes, then both
time.Date(1955, time.May, 1, 0, 0, 0, 0, loc)
and
dt.Date{Year: 1955, Month: time.May, Day: 1}.In(loc)
return 23:00:00 on April 30, 1955.
In panics if loc is nil.
func (Date) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output is the result of d.String().
func (*Date) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The date is expected to be a string in a format accepted by ParseDate.
type DateTime ¶
A DateTime represents a date and time.
func DateTimeOf ¶
DateTimeOf returns the DateTime in which a time occurs in that time's location.
func ParseDateTime ¶
ParseDateTime parses a string and returns the DateTime it represents. ParseDateTime accepts a variant of the RFC3339 date-time format that omits the time offset but includes an optional fractional time, as described in ParseTime. Informally, the accepted format is
YYYY-MM-DDTHH:MM:SS[.FFFFFFFFF]
where the 'T' may be a lower-case 't'.
func (DateTime) In ¶
In returns the time corresponding to the DateTime in the given location.
If the time is missing or ambigous at the location, In returns the same result as time.Date. For example, if loc is America/Indiana/Vincennes, then both
time.Date(1955, time.May, 1, 0, 30, 0, 0, loc)
and
dt.DateTime{
dt.Date{Year: 1955, Month: time.May, Day: 1}},
dt.Time{Minute: 30}}.In(loc)
return 23:30:00 on April 30, 1955.
In panics if loc is nil.
func (DateTime) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output is the result of dt.String().
func (*DateTime) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The datetime is expected to be a string in a format accepted by ParseDateTime
type Now ¶
Now now struct
func (*Now) BeginningOfDay ¶
BeginningOfDay beginning of day
func (*Now) BeginningOfHalf ¶
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
type Time ¶
type Time struct {
Hour int // The hour of the day in 24-hour format; range [0-23]
Minute int // The minute of the hour; range [0-59]
Valid bool
}
A Time represents a time with nanosecond precision.
This type does not include location information, and therefore does not describe a unique moment in time.
This type exists to represent the TIME type in storage-based APIs like BigQuery. Most operations on Times are unlikely to be meaningful. Prefer the DateTime type.
func ParseTime ¶
ParseTime parses a string and returns the time value it represents. ParseTime accepts an extended form of the RFC3339 partial-time format. After the HH:MM:SS part of the string, an optional fractional part may appear, consisting of a decimal point followed by one to nine decimal digits. (RFC3339 admits only one digit after the decimal point).
func TimeOf ¶
TimeOf returns the Time representing the time of day in which a time occurs in that time's location. It ignores the date.
func (Time) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output is the result of d.String().
func (Time) String ¶
String returns the date in the format described in ParseTime. If Valid is not true, it will return empty string
func (*Time) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The time is expected to be a string in a format accepted by ParseTime.