gotime

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 5 Imported by: 13

README

Golang

📦 Golang 时间

godoc goproxy.cn goreportcard.com deps.dev

安装

go get -v -u go.dtapp.net/gotime@v1.0.8

使用

package main

import (
	"go.dtapp.net/gotime"
	"testing"
)

// TestVerification 验证字符串是否为时间
func TestVerification(t *testing.T) {
	t.Log(gotime.Verification("2022-02-05 00:00:00", gotime.DateTimeFormat))
}

Documentation

Index

Constants

View Source
const (
	DateTimeFormat       = "2006-01-02 15:04:05"
	DateTimeShrinkFormat = "2006-01-02 15:04"
	DateFormat           = "2006-01-02"
	TimeFormat           = "15:04:05"
)
View Source
const (
	DateTimeZhFormat       = "2006年01月02日 15点04分05秒"
	DateTimeZhShrinkFormat = "2006年01月02日 15点04分"
	DateZhFormat           = "2006年01月02日"
	TimeZhFormat           = "15点04分05秒"
	TimeZhShrinkFormat     = "15点04分"
)
View Source
const (
	RFC3339Format       = time.RFC3339
	Iso8601Format       = "2006-01-02T15:04:05-07:00"
	CookieFormat        = "Monday, 02-Jan-2006 15:04:05 MST"
	RFC1036Format       = "Mon, 02 Jan 06 15:04:05 -0700"
	RFC7231Format       = "Mon, 02 Jan 2006 15:04:05 GMT"
	DayDateTimeFormat   = "Mon, Jan 2, 2006 3:04 PM"
	ShortDateTimeFormat = "20060102150405"
	ShortDateFormat     = "20060102"
	ShortTimeFormat     = "150405"
)

时间格式化常量

View Source
const (
	YearsPerMillennium = 1000 // 每千年1000年
	YearsPerCentury    = 100  // 每世纪100年
	YearsPerDecade     = 10   // 每十年10年
	QuartersPerYear    = 4    // 每年4季度
	MonthsPerYear      = 12   // 每年12月
	MonthsPerQuarter   = 3    // 每季度3月
	WeeksPerNormalYear = 52   // 每常规年52周

	WeeksPerMonth              = 4       // 每月4周
	DaysPerLeapYear            = 366     // 每闰年366天
	DaysPerNormalYear          = 365     // 每常规年365天
	DaysPerWeek                = 7       // 每周7天
	HoursPerWeek               = 168     // 每周168小时
	HoursPerDay                = 24      // 每天24小时
	MinutesPerDay              = 1440    // 每天1440分钟
	MinutesPerHour             = 60      // 每小时60分钟
	SecondsPerWeek             = 604800  // 每周604800秒
	SecondsPerDay              = 86400   // 每天86400秒
	SecondsPerHour             = 3600    // 每小时3600秒
	SecondsPerMinute           = 60      // 每分钟60秒
	MillisecondsPerSecond      = 1000    // 每秒1000毫秒
	MicrosecondsPerMillisecond = 1000    // 每毫秒1000微秒
	MicrosecondsPerSecond      = 1000000 // 每秒1000000微秒
)

数字常量

View Source
const Version = "1.0.8"

Variables

This section is empty.

Functions

func Verification added in v1.0.5

func Verification(str, layout string) (resp time.Time, err error)

Verification 验证字符串是否为时间

Types

type Pro

type Pro struct {
	Time time.Time
	// contains filtered or unexported fields
}

Pro 结构体

func Current

func Current() Pro

Current 获取当前的时间

func NewPro

func NewPro() Pro

NewPro 初始化结构体

func SetCurrent

func SetCurrent(sTime time.Time) Pro

SetCurrent 设置当前的时间

func SetCurrentMillisecondUnix added in v1.0.6

func SetCurrentMillisecondUnix(ts int64) Pro

SetCurrentMillisecondUnix 设置当前的时间 毫秒Unix时间戳

func SetCurrentParse

func SetCurrentParse(str string) Pro

SetCurrentParse 设置当前的时间

func SetCurrentUnix

func SetCurrentUnix(ts int64) Pro

SetCurrentUnix 设置当前的时间 Unix时间戳

func Tomorrow

func Tomorrow() Pro

Tomorrow 明天

func Yesterday

func Yesterday() Pro

Yesterday 昨天

func (Pro) AfterDay

func (p Pro) AfterDay(day int) Pro

AfterDay 获取n天后的时间

func (Pro) AfterHour

func (p Pro) AfterHour(hour int64) Pro

AfterHour 获取n小时后的时间

func (Pro) AfterMinute

func (p Pro) AfterMinute(seconds int64) Pro

AfterMinute 获取n分钟后的时间

func (Pro) AfterSeconds

func (p Pro) AfterSeconds(seconds int64) Pro

AfterSeconds 获取n秒后的时间

func (Pro) BeforeDay

func (p Pro) BeforeDay(day int) Pro

BeforeDay 获取n天前的时间

func (Pro) BeforeHour

func (p Pro) BeforeHour(hour int64) Pro

BeforeHour 获取n小时前的时间

func (Pro) BeforeMinute

func (p Pro) BeforeMinute(seconds int64) Pro

BeforeMinute 获取n分钟前的时间

func (Pro) BeforeSeconds

func (p Pro) BeforeSeconds(seconds int64) Pro

BeforeSeconds 获取n秒前的时间

func (Pro) Between

func (p Pro) Between(start time.Time, end time.Time) bool

Between 是否在两个时间之间(不包括这两个时间)

func (Pro) BetweenIncludedBoth

func (p Pro) BetweenIncludedBoth(start time.Time, end time.Time) bool

BetweenIncludedBoth 是否在两个时间之间(包括这两个时间)

func (Pro) BetweenIncludedEnd

func (p Pro) BetweenIncludedEnd(start time.Time, end time.Time) bool

BetweenIncludedEnd 是否在两个时间之间(包括结束时间)

func (Pro) BetweenIncludedStart

func (p Pro) BetweenIncludedStart(start time.Time, end time.Time) bool

BetweenIncludedStart 是否在两个时间之间(包括开始时间)

func (Pro) Bson

func (p Pro) Bson() string

Bson mongoDB

func (Pro) DiffInHour

func (p Pro) DiffInHour(t2 time.Time) (hour int64)

DiffInHour 相差多少小时

func (Pro) DiffInHourWithAbs

func (p Pro) DiffInHourWithAbs(t2 time.Time) (hour int64)

DiffInHourWithAbs 相差多少小时(绝对值)

func (Pro) DiffInMinutes

func (p Pro) DiffInMinutes(t2 time.Time) (hour int64)

DiffInMinutes 相差多少分钟

func (Pro) DiffInMinutesWithAbs

func (p Pro) DiffInMinutesWithAbs(t2 time.Time) (hour int64)

DiffInMinutesWithAbs 相差多少分钟(绝对值)

func (Pro) DiffInSecond

func (p Pro) DiffInSecond(t2 time.Time) (hour int64)

DiffInSecond 相差多少秒

func (Pro) DiffInSecondWithAbs

func (p Pro) DiffInSecondWithAbs(t2 time.Time) (hour int64)

DiffInSecondWithAbs 相差多少秒(绝对值)

func (Pro) EndOfCentury

func (p Pro) EndOfCentury() Pro

EndOfCentury 本世纪结束时间

func (Pro) EndOfDay

func (p Pro) EndOfDay() Pro

EndOfDay 本日结束时间

func (Pro) EndOfDecade

func (p Pro) EndOfDecade() Pro

EndOfDecade 本年代结束时间

func (Pro) EndOfMonth

func (p Pro) EndOfMonth() Pro

EndOfMonth 本月结束时间

func (Pro) EndOfQuarter

func (p Pro) EndOfQuarter() Pro

EndOfQuarter 本季度结束时间

func (Pro) EndOfYear

func (p Pro) EndOfYear() Pro

EndOfYear 本年结束时间

func (Pro) Eq

func (p Pro) Eq(t2 time.Time) bool

Eq 是否等于

func (Pro) Format

func (p Pro) Format() string

Format 今天此刻格式化

func (Pro) Gt

func (p Pro) Gt(t2 time.Time) bool

Gt 是否大于

func (Pro) Gte

func (p Pro) Gte(t2 time.Time) bool

Gte 是否大于等于

func (Pro) Lt

func (p Pro) Lt(t2 time.Time) bool

Lt 是否小于

func (Pro) Lte

func (p Pro) Lte(t2 time.Time) bool

Lte 是否小于等于

func (Pro) Month

func (p Pro) Month() int64

Month 获取当前月

func (Pro) MonthOfYear

func (p Pro) MonthOfYear() int64

MonthOfYear 获取本年的第几月

func (Pro) Ne

func (p Pro) Ne(t2 time.Time) bool

Ne 是否不等于

func (Pro) Now

func (p Pro) Now() time.Time

Now 今天此刻

func (Pro) Quarter

func (p Pro) Quarter() (quarter int)

Quarter 获取当前季度

func (Pro) SetFormat

func (p Pro) SetFormat(layout string) string

SetFormat 格式化

func (Pro) StartOfCentury

func (p Pro) StartOfCentury() Pro

StartOfCentury 本世纪开始时间

func (Pro) StartOfDay

func (p Pro) StartOfDay() Pro

StartOfDay 本日开始时间

func (Pro) StartOfDecade

func (p Pro) StartOfDecade() Pro

StartOfDecade 本年代开始时间

func (Pro) StartOfMonth

func (p Pro) StartOfMonth() Pro

StartOfMonth 本月开始时间

func (Pro) StartOfQuarter

func (p Pro) StartOfQuarter() Pro

StartOfQuarter 本季度开始时间

func (Pro) StartOfYear

func (p Pro) StartOfYear() Pro

StartOfYear 本年开始时间

func (Pro) Timestamp

func (p Pro) Timestamp() int64

Timestamp 今天此刻时间戳

func (Pro) TimestampWithMicrosecond

func (p Pro) TimestampWithMicrosecond() int64

TimestampWithMicrosecond 今天微秒级时间戳

func (Pro) TimestampWithMillisecond

func (p Pro) TimestampWithMillisecond() int64

TimestampWithMillisecond 今天毫秒级时间戳

func (Pro) TimestampWithNanosecond

func (p Pro) TimestampWithNanosecond() int64

TimestampWithNanosecond 今天纳秒级时间戳

func (Pro) TimestampWithSecond

func (p Pro) TimestampWithSecond() int64

TimestampWithSecond 今天此刻时间戳

func (Pro) ToDateFormat

func (p Pro) ToDateFormat() string

ToDateFormat 今天此刻日期

func (Pro) ToDateFormatTime added in v1.0.7

func (p Pro) ToDateFormatTime() time.Time

ToDateFormatTime 今天此刻日期

func (Pro) ToTimeFormat

func (p Pro) ToTimeFormat() string

ToTimeFormat 今天此刻时间

Jump to

Keyboard shortcuts

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