Documentation
¶
Index ¶
- Variables
- func SetLanguage(language string)
- func SetLocales(locales I18nLocales)
- func SetTimeZone(timezone string)
- type AgoOptions
- type DateTime
- func (dt *DateTime) Add(d time.Duration) *DateTime
- func (dt *DateTime) AddDate(years int, months int, days int) *DateTime
- func (dt *DateTime) After(t *DateTime) bool
- func (dt *DateTime) Ago(opts ...*AgoOptions) string
- func (dt *DateTime) Before(t *DateTime) bool
- func (dt *DateTime) Date() (year, month, day int)
- func (dt *DateTime) Day() int
- func (dt *DateTime) EndOfDay() *DateTime
- func (dt *DateTime) EndOfHour() *DateTime
- func (dt *DateTime) EndOfMinute() *DateTime
- func (dt *DateTime) EndOfMonth() *DateTime
- func (dt *DateTime) EndOfQuarter() *DateTime
- func (dt *DateTime) EndOfWeek() *DateTime
- func (dt *DateTime) EndOfYear() *DateTime
- func (dt *DateTime) Equal(t *DateTime) bool
- func (dt *DateTime) Format(pattern ...string) string
- func (dt *DateTime) GetTimeZone() string
- func (dt *DateTime) Hour() int
- func (dt *DateTime) Location() *time.Location
- func (dt *DateTime) MarshalJSON() ([]byte, error)
- func (dt *DateTime) Millisecond() int
- func (dt *DateTime) Minute() int
- func (dt *DateTime) Month() int
- func (dt *DateTime) Second() int
- func (dt *DateTime) SetTimeZone(timezone string) error
- func (dt *DateTime) StartOfDay() *DateTime
- func (dt *DateTime) StartOfHour() *DateTime
- func (dt *DateTime) StartOfMinute() *DateTime
- func (dt *DateTime) StartOfMonth() *DateTime
- func (dt *DateTime) StartOfQuarter() *DateTime
- func (dt *DateTime) StartOfWeek() *DateTime
- func (dt *DateTime) StartOfYear() *DateTime
- func (dt *DateTime) String() string
- func (dt *DateTime) Sub(t *DateTime) time.Duration
- func (dt *DateTime) Time() time.Time
- func (dt *DateTime) Timestamp() int64
- func (dt *DateTime) Unix() int64
- func (dt *DateTime) UnixMilli() int64
- func (dt *DateTime) UnixNano() int64
- func (dt *DateTime) UnmarshalJSON(data []byte) error
- func (dt *DateTime) WeekDay() int
- func (dt *DateTime) Year() int
- type I18nLocales
- type I18nTranslations
Constants ¶
This section is empty.
Variables ¶
var AgoPattern = map[string]string{
"now": "just now",
"second": "%d second ago",
"minute": "%d minute ago",
"hour": "%d hour ago",
"day": "%d day ago",
"week": "%d week ago",
"month": "%d month ago",
"year": "%d year ago",
}
AgoPattern is the pattern for Ago.
var DefaultFormatPattern = "YYYY-MM-DD HH:mm:ss"
DefaultFormatPattern is the default format pattern.
var Language = "en-US"
Language is the language.
var Locales = I18nLocales{}
Locales is the locales.
var LocalesWeekDays = []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
LocalesWeekDays is the week days.
var LocalesWeekDaysMin = []string{"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}
LocalesWeekDaysMin is the week days in minium.
var LocalesWeekDaysShort = []string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
LocalesWeekDaysShort is the week days in short.
var TimeZoneForce = ""
TimeZoneForce will force to override datetime instance time zone
default is empty string, means no force time zone, use datetime self timezone, it is local timezone for example, set as Asia/Shanghai, Format will use Asia/Shanghai override internal time zone unless it has call SetTimeZone before
var Version = "1.3.2"
Version is the version of this package.
Functions ¶
func SetTimeZone ¶ added in v1.1.0
func SetTimeZone(timezone string)
SetTimeZone sets the global time zone of the datetime.
Types ¶
type AgoOptions ¶ added in v1.2.0
type AgoOptions struct {
Diff *DateTime
}
AgoOptions is the options for Ago.
type DateTime ¶
type DateTime struct {
// contains filtered or unexported fields
}
DateTime is a struct that represents a datetime.
func FromDate ¶
FromDate returns a DateTime from a Date. Example:
FromDate(2022, 4, 12, 10, 39, 12) FromDate(2022, 4, 12, 10, 39, 12, "Asia/Shanghai")
func FromPattern ¶
FromPattern returns a DateTime from a pattern(layout) and a datetime string. Example:
pattern := "YYYY/MM/DD HH:mm:ss" datetime := "2022/04/12 10:39:12" dt, err := FromPattern(pattern, datetime) dt, err := FromPattern(pattern, datetime, "Asia/Shanghai") Available pattern(layout): (file: /usr/local/go/src/time/format.go) time.Layout = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order. time.ANSIC = "Mon Jan _2 15:04:05 2006" time.UnixDate = "Mon Jan _2 15:04:05 MST 2006" time.RubyDate = "Mon Jan 02 15:04:05 -0700 2006" time.RFC822 = "02 Jan 06 15:04 MST" time.RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone time.RFC850 = "Monday, 02-Jan-06 15:04:05 MST" time.RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST" time.RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone time.RFC3339 = "2006-01-02T15:04:05Z07:00" time.RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" time.Kitchen = "3:04PM" // Handy time stamps. time.Stamp = "Jan _2 15:04:05" time.StampMilli = "Jan _2 15:04:05.000" time.StampMicro = "Jan _2 15:04:05.000000" time.StampNano = "Jan _2 15:04:05.000000000"
func FromTime ¶
FromTime returns a DateTime from time.Time. Example:
t := time.Now() dt := FromTime(t)
func New ¶
New returns a DateTime Support:
time.Time example: New(time.Now())
YYYY/MM/DD HH:mm:ss, datetime string example: New("YYYY/MM/DD HH:mm:ss", "2022/04/12 10:39:12") New("YYYY/MM/DD HH:mm:ss", "2022/04/12 10:39:12", "Asia/Shanghai")
year, month, day, hour, minute, second example: New(2022, 4, 12, 10, 39, 12) New(2022, 4, 12, 10, 39, 12, "Asia/Shanghai")
func (*DateTime) Ago ¶ added in v1.2.0
func (dt *DateTime) Ago(opts ...*AgoOptions) string
Ago return time ago from now.
func (*DateTime) EndOfMinute ¶ added in v1.0.3
EndOfMinute returns the end of the hour.
func (*DateTime) EndOfMonth ¶
EndOfMonth returns the end of the month.
func (*DateTime) EndOfQuarter ¶ added in v1.0.3
EndOfQuarter returns the end of the quarter.
func (*DateTime) GetTimeZone ¶ added in v1.1.0
GetTimeZone gets the time zone of the datetime.
func (*DateTime) MarshalJSON ¶ added in v1.3.1
MarshalJSON implements the json.Marshaler interface.
func (*DateTime) Millisecond ¶
Millisecond returns the milliseconds.
func (*DateTime) SetTimeZone ¶
SetTimeZone sets the time zone of the datetime.
func (*DateTime) StartOfDay ¶
StartOfDay returns the start of the day.
func (*DateTime) StartOfHour ¶
StartOfHour returns the start of the hour.
func (*DateTime) StartOfMinute ¶ added in v1.0.3
StartOfMinute returns the start of the hour.
func (*DateTime) StartOfMonth ¶
StartOfMonth returns the start of the month.
func (*DateTime) StartOfQuarter ¶ added in v1.0.3
StartOfQuarter returns the end of the hour.
func (*DateTime) StartOfWeek ¶
StartOfWeek returns the start of the week.
func (*DateTime) StartOfYear ¶
StartOfYear returns the start of the year.
func (*DateTime) UnixMilli ¶ added in v1.3.0
UnixMilli returns the number of milliseconds since the Unix epoch.
func (*DateTime) UnixNano ¶ added in v1.3.0
UnixNano returns the number of nanoseconds since the Unix epoch.
func (*DateTime) UnmarshalJSON ¶ added in v1.3.1
UnmarshalJSON implements the json.Unmarshaler interface.
type I18nLocales ¶ added in v1.2.0
type I18nLocales map[string]I18nTranslations
I18nLocales is the locales.
type I18nTranslations ¶ added in v1.2.0
I18nTranslations is the translations.