Documentation
¶
Index ¶
- Constants
- func AtFunc()
- func CurrentUnixMillis() int64
- func Format(layout string, t time.Time) string
- func FormatCommon(t time.Time) string
- func GetNow() string
- func GetNow2TargetTime(targetTime time.Time) (time.Duration, error)
- func GetNowDate() string
- func GetNowTime() string
- func GetTarget2NowTime(targetTime time.Time) (time.Duration, error)
- func GetTimeFormat(duration time.Duration) string
- func GetTimeRound(duration time.Duration) (time.Time, error)
- func GetTwoTimeSub(startime, endtime time.Time) (time.Duration, error)
- func HowCost(start time.Time, limit time.Duration, limitFunc CostCallFunc)
- func HowCostInTrack(start time.Time, limit time.Duration, track interface{}, ...)
- func ParseLocal(targetTimeStr string) (time.Time, error)
- func ParseMillSecond(millSecond int64) time.Duration
- func ParseSecond(second int64) time.Duration
- func Time_UnixMillisecond(millisecond int64) time.Time
- func Time_UnixSecond(second int64) time.Time
- func UnixMicrosecond(t time.Time) int64
- func UnixMillisecond(t time.Time) int64
- func UnixSecond(t time.Time) int64
- type CostCallFunc
- type JsonTime
- type TimeUnit
Constants ¶
const ( Format_common_minus = "2006-01-02 15:04:05" Format_IS08601 = "2006-01-02 15:04:05.000" //yyyy-MM-dd HH:mm:ss.SSS Format_common_slash = "2006/01/02 15:04:05" Format_common_date = "2006-01-02" Format_common_date2 = "2006/01/02" Format_common_time = "15:04:05" // TimeFormat is the time format to use when generating times in HTTP // headers. It is like time.RFC1123 but hard-codes GMT as the time // zone. The time being formatted must be in UTC for Format to // generate the correct format. // // For parsing this time format, see ParseTime. // from golang/http/fs.go Format_standard_GMT = "Mon, 02 Jan 2006 15:04:05 GMT" )
https://www.cnblogs.com/sandea/p/9696712.html 时间可分为时间点与时间段 ,提供了以下两种基础类型 - 时间点(Time) - 时间段(Duration)
除此之外 golang 也提供��了以下类型,做一些特定的业务 - 时区(Location) - Ticker - Timer(定时器)
Variables ¶
This section is empty.
Functions ¶
func FormatCommon ¶ added in v0.0.9
func GetNow2TargetTime ¶
获取现在的时间 距离 目标时间之间 剩余时间段,
func GetNowDate ¶ added in v0.0.8
func GetNowDate() string
func GetNowTime ¶ added in v0.0.8
func GetNowTime() string
func GetTarget2NowTime ¶
获取过去时间 到 现在时间 的时间段
func GetTimeFormat ¶
Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged. 按照常规使用字符串 "yyyy-MM-dd HH:mm:ss" 来格式化时间.
func GetTwoTimeSub ¶
返回两个时间段时间的 时间段
func HowCost ¶ added in v0.0.10
func HowCost(start time.Time, limit time.Duration, limitFunc CostCallFunc)
use example :
func test() { defer HowCost(time.Now(), time.Second, LogCostCallFunc) // do some work }
func HowCostInTrack ¶ added in v0.0.10
func HowCostInTrack(start time.Time, limit time.Duration, track interface{}, limitFunc CostCallFunc)
func ParseMillSecond ¶ added in v0.0.9
将毫秒单位的时间段转换为 以纳秒为单位的time.Duration类型对象
func ParseSecond ¶ added in v0.0.9
将秒单位的时间段转换为 time.Duration类型对象
func Time_UnixMillisecond ¶ added in v0.0.6
毫秒单位的时间戳转换为time类型 1ms == 1000us (微秒) 1us == 1000ns (纳秒) 1ms == 1000us * 1000ns == 1*10^6(ns)
func Time_UnixSecond ¶ added in v0.0.6
秒单位的时间戳 转为 time类型
Types ¶
type CostCallFunc ¶ added in v0.0.10
var ( EmptyCostCallFunc CostCallFunc = func(realCost time.Duration, track interface{}) { } LogCostCallFunc CostCallFunc = func(realCost time.Duration, track interface{}) { fmt.Println(realCost) } )
type JsonTime ¶ added in v0.0.8
func NewJsonTime ¶ added in v0.0.8
func NowJsonTime ¶ added in v0.0.8
func NowJsonTime() JsonTime
func (JsonTime) MarshalJSON ¶ added in v0.0.8
所以我们只需定义一个内嵌time.Time的结构体,并重写MarshalJSON方法,然后在定义model的时候把time.Time类型替换为我们自己的类型即可。但是在gorm中只重写MarshalJSON是不够的,只写这个方法会在写数据库的时候会提示delete_at字段不存在,需要加上database/sql的Value和Scan方法 https://github.com/jinzhu/gorm/issues/1611#issuecomment-329654638。