date

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

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

func CalcPeriodStartByDirection(ts time.Time, unit int64, period, direction string) int64

CalcPeriodStartByDirection calc period start time

func Format

func Format(time time.Time, layout string) string

时间格式化

func FromTimestamp

func FromTimestamp(timestamp int64) time.Time

毫秒时间戳转时间

func FromUnix

func FromUnix(unix int64) time.Time

秒时间戳转时间

func GetDay

func GetDay(time time.Time) int

return yyyyMMdd

func IsSameDay

func IsSameDay(s, d, unit int64) bool

IsSameDay if is some day return true

func NowTimestamp

func NowTimestamp() int64

当前毫秒时间戳

func NowUnix

func NowUnix() int64

秒时间戳

func Parse

func Parse(timeStr, layout string) (time.Time, error)

字符串时间转时间类型

func PrettyTime

func PrettyTime(milliseconds int64) string

*

  • 将时间格式换成 xx秒前,xx分钟前...
  • 规则:
  • 59秒--->刚刚
  • 1-59分钟--->x分钟前(23分钟前)
  • 1-24小时--->x小时前(5小时前)
  • 昨天--->昨天 hh:mm(昨天 16:15)
  • 前天--->前天 hh:mm(前天 16:15)
  • 前天以后--->mm-dd(2月18日)

func Timestamp

func Timestamp(t time.Time) int64

毫秒时间戳

func WithTimeAsStartOfDay

func WithTimeAsStartOfDay(t time.Time) time.Time

返回指定时间当天的开始时间

Types

type Period

type Period struct {
	// contains filtered or unexported fields
}

Period period struct

func CalcPeriodStartEnd

func CalcPeriodStartEnd(t time.Time, period string) *Period

CalcPeriodStartEnd giving time and period, calc period start time and end time default period is Day

func (*Period) End

func (p *Period) End() time.Time

End get period end time

func (*Period) Start

func (p *Period) Start() time.Time

Start get period start time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL