Documentation
¶
Index ¶
- Constants
- Variables
- func CalcPeriodStartByDirection(ts time.Time, unit int64, period, direction string) int64
- func Format(time time.Time, layout string) string
- func FromTimestamp(timestamp int64) time.Time
- func FromUnix(unix int64) time.Time
- func GetDay(time time.Time) int
- func IsSameDay(s, d, unit int64) bool
- func NowTimestamp() int64
- func NowUnix() int64
- func Parse(timeStr, layout string) (time.Time, error)
- func PrettyTime(milliseconds int64) string
- func Timestamp(t time.Time) int64
- func WithTimeAsStartOfDay(t time.Time) time.Time
- type Period
Constants ¶
View Source
const ( FmtDate = "2006-01-02" FmtTime = "15:04:05" FmtDateTime = "2006-01-02 15:04:05" FmtDateTimeNoSeconds = "2006-01-02 15:04" )
View Source
const ( Prev = "previous" Next = "next" Cur = "current" )
direction of time
View Source
const ( Minute = "minute" Hour = "hour" Day = "day" Week = "week" )
time period
View Source
const ( SecUnit int64 = 1 MilliSecUnit int64 = 1000 )
unit
Variables ¶
View Source
var ( SecPerMin int64 = 60 SecPerHour = 60 * SecPerMin SecPerDay = 24 * SecPerHour )
interval of time by second unit
Functions ¶
func CalcPeriodStartByDirection ¶
CalcPeriodStartByDirection calc period start time
func PrettyTime ¶
*
- 将时间格式换成 xx秒前,xx分钟前...
- 规则:
- 59秒--->刚刚
- 1-59分钟--->x分钟前(23分钟前)
- 1-24小时--->x小时前(5小时前)
- 昨天--->昨天 hh:mm(昨天 16:15)
- 前天--->前天 hh:mm(前天 16:15)
- 前天以后--->mm-dd(2月18日)
Types ¶
type Period ¶
type Period struct {
// contains filtered or unexported fields
}
Period period struct
func CalcPeriodStartEnd ¶
CalcPeriodStartEnd giving time and period, calc period start time and end time default period is Day
Click to show internal directories.
Click to hide internal directories.