Documentation ¶
Overview ¶
Package timex provides an enhanced time.Time implementation. Add more commonly used functional methods.
such as: DayStart(), DayAfter(), DayAgo(), DateFormat() and more.
Index ¶
- Constants
- Variables
- func AddDay(t time.Time, day int) time.Time
- func AddHour(t time.Time, hour int) time.Time
- func AddMinutes(t time.Time, minutes int) time.Time
- func AddSeconds(t time.Time, seconds int) time.Time
- func Date(t time.Time, template string) string
- func DateFormat(t time.Time, template string) string
- func DayEnd(t time.Time) time.Time
- func DayStart(t time.Time) time.Time
- func Format(t time.Time) string
- func FormatBy(t time.Time, layout string) string
- func FormatByTpl(t time.Time, template string) string
- func FormatUnix(sec int64) string
- func FormatUnixBy(sec int64, layout string) string
- func FormatUnixByTpl(sec int64, template string) string
- func HourEnd(t time.Time) time.Time
- func HourStart(t time.Time) time.Time
- func HowLongAgo(sec int64) string
- func NowAddDay(day int) time.Time
- func NowAddHour(hour int) time.Time
- func NowAddMinutes(minutes int) time.Time
- func NowAddSeconds(seconds int) time.Time
- func NowHourEnd() time.Time
- func NowHourStart() time.Time
- func NowUnix() int64
- func SetLocalByName(tzName string) error
- func ToDuration(s string) (time.Duration, error)
- func ToLayout(template string) string
- func TodayEnd() time.Time
- func TodayStart() time.Time
- type Time
- func FromDate(s string, template ...string) (*Time, error)
- func FromString(s string, layouts ...string) (*Time, error)
- func FromTime(t time.Time) *Time
- func FromUnix(sec int64) *Time
- func Local() *Time
- func LocalByName(tzName string) *Time
- func New(t time.Time) *Time
- func Now() *Time
- func Wrap(t time.Time) *Time
- func (t *Time) AddDay(day int) *Time
- func (t *Time) AddHour(hours int) *Time
- func (t *Time) AddMinutes(minutes int) *Time
- func (t *Time) AddSeconds(seconds int) *Time
- func (t *Time) CustomHMS(hour, min, sec int) *Time
- func (t *Time) DateFormat(template string) string
- func (t *Time) Datetime() string
- func (t *Time) DayAfter(day int) *Time
- func (t *Time) DayAgo(day int) *Time
- func (t *Time) DayEnd() *Time
- func (t *Time) DayStart() *Time
- func (t Time) Diff(u time.Time) time.Duration
- func (t Time) DiffSec(u time.Time) int
- func (t Time) DiffUnix(u int64) int
- func (t *Time) Format(layout string) string
- func (t *Time) HourEnd() *Time
- func (t *Time) HourStart() *Time
- func (t Time) HowLongAgo(before time.Time) string
- func (t *Time) IsAfter(u time.Time) bool
- func (t *Time) IsAfterUnix(ux int64) bool
- func (t *Time) IsBefore(u time.Time) bool
- func (t *Time) IsBeforeUnix(ux int64) bool
- func (t *Time) SubDay(day int) *Time
- func (t *Time) SubHour(hours int) *Time
- func (t *Time) SubMinutes(minutes int) *Time
- func (t *Time) SubSeconds(seconds int) *Time
- func (t Time) SubUnix(u time.Time) int
- func (t Time) T() time.Time
- func (t Time) Timestamp() int64
- func (t *Time) Tomorrow() *Time
- func (t *Time) TplFormat(template string) string
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t *Time) UnmarshalText(data []byte) error
- func (t *Time) Yesterday() *Time
- type TimeX
Constants ¶
const ( OneSecond = 1 OneMinSec = 60 OneHourSec = 3600 OneDaySec = 86400 OneWeekSec = 7 * 86400 Second = time.Second OneMin = time.Minute OneHour = time.Hour OneDay = 24 * time.Hour OneWeek = 7 * 24 * time.Hour DatetimeLayout = "2006-01-02 15:04:05" DateOnlyLayout = "2006-01-02" TimeOnlyLayout = "15:04:05" )
provide some commonly time consts
Variables ¶
var (
// DefaultLayout template for format time
DefaultLayout = "2006-01-02 15:04:05"
)
Functions ¶
func AddMinutes ¶
AddMinutes add some minutes time for given time
func AddSeconds ¶
AddSeconds add some seconds time for given time
func DateFormat ¶ added in v0.5.1
DateFormat format time by given date template. see ToLayout()
func FormatByTpl ¶ added in v0.5.1
FormatByTpl format time by given date template. see ToLayout()
func FormatUnixBy ¶
FormatUnixBy format time seconds use given layout
func FormatUnixByTpl ¶ added in v0.5.1
FormatUnixByTpl format time seconds use given date template. see ToLayout()
func HowLongAgo ¶ added in v0.5.1
HowLongAgo format given timestamp to string.
func NowAddMinutes ¶
NowAddMinutes add some minutes time from now
func NowAddSeconds ¶
NowAddSeconds add some seconds time from now
func SetLocalByName ¶
SetLocalByName set local by tz name. eg: UTC, PRC
func ToDuration ¶ added in v0.5.6
ToDuration parses a duration string. such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
Types ¶
type Time ¶ added in v0.5.13
type Time struct { time.Time // Layout set the default date format layout. default use DefaultLayout Layout string }
Time an enhanced time.Time implementation.
func FromString ¶ added in v0.5.1
FromString create from datetime string. see strutil.ToTime()
func (*Time) AddMinutes ¶ added in v0.5.13
AddMinutes add some minutes time for the time
func (*Time) AddSeconds ¶ added in v0.5.13
AddSeconds add some seconds time the time
func (*Time) CustomHMS ¶ added in v0.5.13
CustomHMS custom change the hour, minute, second for create new time.
func (*Time) DateFormat ¶ added in v0.5.13
DateFormat use input template format time to date. see ToLayout()
func (*Time) Datetime ¶ added in v0.5.13
Datetime use DefaultLayout format time to date. see Format()
func (*Time) DayAfter ¶ added in v0.5.13
DayAfter get some day after time for the time. alias of Time.AddDay()
func (*Time) Format ¶ added in v0.5.13
Format returns a textual representation of the time value formatted according to the layout defined by the argument.
see time.Time.Format()
func (Time) HowLongAgo ¶ added in v0.5.13
HowLongAgo format diff time to string.
func (*Time) IsAfterUnix ¶ added in v0.5.13
IsAfterUnix the given unix timestamp
func (*Time) IsBeforeUnix ¶ added in v0.5.13
IsBeforeUnix the given unix timestamp
func (*Time) SubMinutes ¶ added in v0.5.13
SubMinutes add some minutes time for the time
func (*Time) SubSeconds ¶ added in v0.5.13
SubSeconds add some seconds time the time
func (*Time) UnmarshalJSON ¶ added in v0.5.13
UnmarshalJSON implements the json.Unmarshaler interface.
Tip: will auto match a format by strutil.ToTime()
func (*Time) UnmarshalText ¶ added in v0.5.13
UnmarshalText implements the encoding.TextUnmarshaler interface.
Tip: will auto match a format by strutil.ToTime()