Documentation
¶
Overview ¶
Package dateutil
@author: xwc1125
Package dateutil @author: xwc1125
Index ¶
- Constants
- Variables
- func CurrentTime() int64
- func CurrentTimeDay() int64
- func CurrentTimeSecond() int64
- func DiffNano(startTime time.Time) (diff int64)
- func Format(t time.Time, format DateFormat) string
- func GetDistanceTime(diffMS int64) string
- func GetDistanceTimeToCurrent(startTime int64) string
- func LoadLocation(loc string) *time.Location
- func MillisecondToTime(t int64) time.Time
- func MustParse(datestr string) time.Time
- func NanoToMillisecond(t int64) int64
- func NanoToSecond(t int64) int64
- func NanoToTime(t int64) time.Time
- func ParseAny(datestr string) (time.Time, error)
- func ParseIn(datestr string, loc *time.Location) (time.Time, error)
- func ParseInLocation(s string, format DateFormat, location *time.Location)
- func ParseLocal(datestr string) (time.Time, error)
- func SecondFormat(t int64, format DateFormat) string
- func SecondToTime(t int64) time.Time
- type DateFormat
- type PrettyAge
- type PrettyDuration
Constants ¶
const (
Day = time.Hour * 24
)
Variables ¶
var SysTimeLocation, _ = time.LoadLocation("Asia/Chongqing")
中国时区
Functions ¶
func GetDistanceTimeToCurrent ¶
GetDistanceTimeToCurrent 传入的是毫秒值
func LoadLocation ¶
func MillisecondToTime ¶
func MustParse ¶
MustParse parse a date, and panic if it can't be parsed. Used for testing. Not recommended for most use-cases.
func NanoToTime ¶
func ParseAny ¶
ParseAny parse an unknown date format, detect the layout, parse. Normal parse. Equivalent Timezone rules as time.Parse()
func ParseIn ¶
ParseIn with Location, equivalent to time.ParseInLocation() timezone/offset rules. Using location arg, if timezone/offset info exists in the datestring, it uses the given location rules for any zone interpretation. That is, MST means one thing when using America/Denver and something else in other locations.
func ParseInLocation ¶
func ParseInLocation(s string, format DateFormat, location *time.Location)
时间转本地化 s时间格式:如"2017-05-11 14:06:06" format:格式 location:时区(Location)
func ParseLocal ¶
ParseLocal Given an unknown date format, detect the layout, using time.Local, parse.
Set Location to time.Local. Same as ParseIn Location but lazily uses the global time.Local variable for Location argument.
denverLoc, _ := time.LoadLocation("America/Denver")
time.Local = denverLoc
t, err := dateparse.ParseLocal("3/1/2014")
Equivalent to:
t, err := dateparse.ParseIn("3/1/2014", denverLoc)
Types ¶
type DateFormat ¶
type DateFormat string
前面是含义,后面是 go 的表示值,多种表示,逗号","分割 年 06,2006 月份 1,01,Jan,January 日 2,02,_2 时 3,03,15,PM,pm,AM,am 分 4,04 秒 5,05 周几 Mon,Monday 时区时差表示 -07,-0700,Z0700,Z07:00,-07:00,MST 时区字母缩写 MST 您看出规律了么!哦是的,你发现了,这里面没有一个是重复的,所有的值表示都唯一对应一个时间部分。 并且涵盖了很多格式组合。
const ( // 时间格式化字符串 Default DateFormat = "2006-01-02 15:04:05" YYYY DateFormat = "2006" YYYY_MM DateFormat = "2006-01" YYYY_7MM DateFormat = "2006/01" YYYY_0MM DateFormat = "2006.01" YYYYMM DateFormat = "200601" YYYY_MM_dd DateFormat = "2006-01-02" YYYY_7MM_7dd DateFormat = "2006/01/02" YYYY_0MM_0dd DateFormat = "2006.01.02" YYYYMMdd DateFormat = "20060102" YYYY_MM_dd8HH0mm DateFormat = "2006-01-02 15:04" YYYY_7MM_7dd8HH0mm DateFormat = "2006/01/02 15:04" YYYY_0MM_0dd8HH0mm DateFormat = "2006.01.02 15:04" YYYYMMddHHmm DateFormat = "200601021504" YYYY_MM_dd8HH0mm0ss DateFormat = "2006-01-02 15:04:05" YYYY_7MM_7dd8HH0mm0ss DateFormat = "2006/01/02 15:04:05" YYYY_0MM_0dd8HH0mm0ss DateFormat = "2006.01.02 15:04:05" YYYYMMddHHmmss DateFormat = "20060102150405" HH0mm0ss DateFormat = "15:04:05" )
func (DateFormat) String ¶
func (d DateFormat) String() string
type PrettyAge ¶
PrettyAge is a pretty printed version of a time.Duration value that rounds the values up to a single most significant unit, days/weeks/years included.
type PrettyDuration ¶
PrettyDuration is a pretty printed version of a time.Duration value that cuts the unnecessary precision off from the formatted textual representation.
func (PrettyDuration) String ¶
func (d PrettyDuration) String() string
String implements the Stringer interface, allowing pretty printing of duration values rounded to three decimals.