dateutil

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 7 Imported by: 15

Documentation

Overview

Package dateutil

@author: xwc1125

Package dateutil @author: xwc1125

Index

Constants

View Source
const (
	Day = time.Hour * 24
)

Variables

View Source
var SysTimeLocation, _ = time.LoadLocation("Asia/Chongqing")

中国时区

Functions

func CurrentTime

func CurrentTime() int64

CurrentTime 返回毫秒

func CurrentTimeDay added in v1.0.3

func CurrentTimeDay() int64

CurrentTimeDay 返回day的时间戳

func CurrentTimeSecond

func CurrentTimeSecond() int64

CurrentTimeSecond 返回秒

func DiffNano added in v1.0.3

func DiffNano(startTime time.Time) (diff int64)

DiffNano 时间差,纳秒

func Format

func Format(t time.Time, format DateFormat) string

格式化输出

func GetDistanceTime

func GetDistanceTime(diffMS int64) string

GetDistanceTime 获取间隔时间错,传入的是毫秒

func GetDistanceTimeToCurrent

func GetDistanceTimeToCurrent(startTime int64) string

GetDistanceTimeToCurrent 传入的是毫秒值

func LoadLocation

func LoadLocation(loc string) *time.Location

func MillisecondToTime

func MillisecondToTime(t int64) time.Time

func MustParse

func MustParse(datestr string) time.Time

MustParse parse a date, and panic if it can't be parsed. Used for testing. Not recommended for most use-cases.

func NanoToMillisecond

func NanoToMillisecond(t int64) int64

NanoToMillisecond 纳秒转毫秒

func NanoToSecond

func NanoToSecond(t int64) int64

NanoToSecond 纳秒转秒

func NanoToTime

func NanoToTime(t int64) time.Time

func ParseAny

func ParseAny(datestr string) (time.Time, error)

ParseAny parse an unknown date format, detect the layout, parse. Normal parse. Equivalent Timezone rules as time.Parse()

func ParseIn

func ParseIn(datestr string, loc *time.Location) (time.Time, error)

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

func ParseLocal(datestr string) (time.Time, error)

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)

func SecondFormat

func SecondFormat(t int64, format DateFormat) string

秒转成format

func SecondToTime

func SecondToTime(t int64) time.Time

秒转time

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

type PrettyAge time.Time

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.

func (PrettyAge) String

func (t PrettyAge) String() string

String implements the Stringer interface, allowing pretty printing of duration values rounded to the most significant time unit.

type PrettyDuration

type PrettyDuration time.Duration

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.

Jump to

Keyboard shortcuts

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