Documentation ¶
Index ¶
- Constants
- Variables
- func BeginOfDay(t time.Time) time.Time
- func BeginOfMonth(t time.Time) time.Time
- func BeginOfWeek(t time.Time, beginAtMonday ...bool) time.Time
- func BeginOfYear(t time.Time) time.Time
- func CurrentDateStr() string
- func CurrentTimeStr(format ...string) string
- func DayOfWeek(t time.Time, beginAtMonday ...bool) int
- func EndOfDay(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfWeek(t time.Time, beginAtMonday ...bool) time.Time
- func EndOfYear(t time.Time) time.Time
- func Format(t time.Time, format ...string) string
- func FormatDate(t time.Time, format ...string) string
- func FromMs(n int64) time.Time
- func FromMsFloat(f float64) time.Time
- func FromNS(n int64) time.Time
- func FromSecondFloat(f float64) time.Time
- func HourOfDay(t time.Time, hour int) time.Time
- func IsValidTimestamp(t time.Time) int
- func LastWeekday(t time.Time, w time.Weekday) time.Time
- func Max(a ...time.Time) time.Time
- func Milliseconds(d time.Duration, decimals ...int) float64
- func Min(a ...time.Time) time.Time
- func NextWeekday(t time.Time, w time.Weekday) time.Time
- func Parse(tmStr string, now ...time.Time) (time.Time, error)
- func ParseNoErr(str string) (t time.Time)
- func Rand(d time.Duration) time.Duration
- func ToFloat(t time.Time, decimals ...int) float64
- func ToFloatStr(t time.Time, decimals ...int) string
- func ToMs(t time.Time) int64
- func ToMsFloat(t time.Time, decimals ...int) float64
- func ToMsFloatStr(t time.Time, decimals ...int) string
- type JsonTime
- func (this JsonTime) Format(format ...string) string
- func (this JsonTime) MarshalJSON() ([]byte, error)
- func (this *JsonTime) Scan(v interface{}) (err error)
- func (this JsonTime) String() string
- func (this *JsonTime) UnmarshalJSON(data []byte) error
- func (this JsonTime) Value() (driver.Value, error)
- type Ticker
Constants ¶
View Source
const ( Day = time.Hour * 24 Week = Day * 7 DateTime = "2006-01-02 15:04:05" DateTimeNano = "2006-01-02 15:04:05.999999999" DateOnly = "2006-01-02" )
Variables ¶
View Source
var ( DefaultFormat = DateTime DefaultBeginOfWeek = time.Monday ZeroTime = time.Unix(0, 0) Greenwich1970 = ZeroTime MinValidTimestamp = time.Unix(1, 0) // timestamp 的最小有效值 MaxValidTimestamp = time.Unix(2147483647, 0) // timestamp 的最大有效值 Local2000 = time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local) // 本地时区时间 2000-01-01 00:00:00.00000000 EndOf2037 = time.Date(2038, 1, 1, 0, 0, 0, -1, time.Local) // 本地时区时间 2037-12-31 23:59:59.99999999 Local2000Sec = Local2000.Unix() // Unix of 本地时区时间 2000-01-01 00:00:00.00000000 EndOf2037Sec = EndOf2037.Unix() // Unix of 本地时区时间 2037-12-31 23:59:59.99999999 Local2000Ms = ToMs(Local2000) // Millisecond of 本地时区时间 2000-01-01 00:00:00.00000000 EndOf2037Ms = ToMs(EndOf2037) // Millisecond of 本地时区时间 2037-12-31 23:59:59.99999999 Local2000Ns = Local2000.UnixNano() // Nanosecond of 本地时区时间 2000-01-01 00:00:00.00000000 )
Functions ¶
func BeginOfWeek ¶
获取一周的开始时间(周日为一周第一天)
func CurrentDateStr ¶
func CurrentDateStr() string
func CurrentTimeStr ¶
func Parse ¶
将字符串转换为 time.Time 类型。支持的格式如下:
数字: 如果小于 MaxInt32,则以秒为单位转换; 否则以毫秒为单位转换。 预定义格式: now|today|yesterday|tomorrow: 当前时间、当天开始时间、昨天开始时间、明天开始时间 {n}{unit}: 当前时间 增加 {n} 个 {unit} 后的结果。 n 可以为负数、 unit 支持 year|month|day(d)|hour(h)|minute(min)|second(sec)|millisecond(ms)|microsecond(us)|nanosecond(ns) 以上格式可以通过英文逗号串联,比如 “tomorrow,2hour,-3min” 表示 “明天01:57” [yyyy-]MM-dd 格式 [yyyy-]MM-dd HH:mm[:ss] 格式
func ParseNoErr ¶
Types ¶
type JsonTime ¶
func ToJsonTime ¶
func (JsonTime) MarshalJSON ¶
MarshalJSON on LocalTime format Time field with %Y-%m-%d %H:%M:%S
func (*JsonTime) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.