dateKit

package module
v0.0.0-...-4e18145 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 5 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dateKit 处理中国农历

Package dateKit 民俗相关日期处理

Index

Constants

View Source
const (
	TimeMillisecond = "Millisecond" // 毫秒
	TimeSeconds     = "Seconds"     // 秒
	TimeMinute      = "Minute"      // 分
	TimeHour        = "Hour"        //小时
	TimeDay         = "Day"         // 天
	TimeWeek        = "Week"        // 周
	TimeMonth       = "Month"       // 月
	TimeYear        = "Year"        // 年
)

Variables

View Source
var (

	// DateLayoutYM 格式化时间的年月模版
	DateLayoutYM = "2006-01"
	// DateLayoutYMD 格式化时间的年月日模版
	DateLayoutYMD = "2006-01-02"
	// DateLayoutHMS 格式化时间的时分秒模版
	DateLayoutHMS = "15:04:05"
	// DateLayoutYMDHMS 格式化时间的年月日时分秒模版
	DateLayoutYMDHMS = "2006-01-02 15:04:05"
	// DateLayoutYMDHMSS 格式化时间的年月日时分秒毫秒模版
	DateLayoutYMDHMSS = "2006-01-02 15:04:05.000"
	// DateLayoutYMDTHMSZ 格式化时间的年月日时分秒毫秒模版
	DateLayoutYMDTHMSZ = "2006-01-02T15:04:05Z"
	// DateLayoutPureYMD 格式化时间的纯年月日模版
	DateLayoutPureYMD = "20060102"
	// DateLayoutPureYMDHMS 格式化时间的纯年月日时分秒模版
	DateLayoutPureYMDHMS = "20060102150405"
	// DateLayoutPureYMDHMSS 格式化时间的纯时分秒毫秒模版
	DateLayoutPureYMDHMSS = "20060102150405000"
)

Functions

func BeginOfDay

func BeginOfDay(date time.Time) string

BeginOfDay 获取某天的开始时间 *

  • @param date 日期
  • @return 返回输入日期的开始时间

func Constellation

func Constellation(date time.Time) (s string)

Constellation 获取当前时间的星座 *

  • @param date 日期
  • @return 返回星座名称

func DateTimeStrToMillStr

func DateTimeStrToMillStr(str string) string

DateTimeStrToMillStr 日期时间字符串转毫秒字符串 *

  • @param str 日期时间字符串 yyyy-MM-dd HH:mm:ss
  • @return 毫秒字符串

func DateTimeStrToSecondStr

func DateTimeStrToSecondStr(str string) string

DateTimeStrToSecondStr 日期时间字符串转秒字符串 *

  • @param str 日期时间字符串 yyyy-MM-dd HH:mm:ss
  • @return 秒字符串

func EndOfDay

func EndOfDay(date time.Time) string

EndOfDay 获取某天的结束时间 *

  • @param date 日期
  • @return 返回输入日期的结束时间

func Format

func Format(dateTime time.Time, format string) string

Format 时间转换为字符串 *

  • @param dateTime 日期
  • @param format 格式
  • @return 格式化后字符串

func FormatDate

func FormatDate(dateTime time.Time) string

FormatDate 时间转换为默认格式 yyyy-MM-dd *

  • @param dateTime 日期
  • @return "yyyy-MM-dd" 格式字符串

func FormatDateTime

func FormatDateTime(dateTime time.Time) string

FormatDateTime 时间转换为默认格式 yyyy-MM-dd HH:mm:ss *

  • @param dateTime 日期
  • @return "yyyy-MM-dd HH:mm:ss" 格式字符串

func FormatWeChatTimeStr

func FormatWeChatTimeStr(chatTimeStr string) string

FormatWeChatTimeStr 格式化时间字符串为微信时间

  • @param chatTimeStr 时间字符串
  • @return 仿微信时间

func GetDay

func GetDay(dateTime time.Time) string

GetDay 获取当前时间的号数 *

  • @param dateTime 日期
  • @return 返回号数

func GetMonth

func GetMonth(dateTime time.Time) string

GetMonth 获取指定时间的月份 *

  • @param dateTime 日期
  • @return 返回月份

func GetYear

func GetYear(dateTime time.Time) string

GetYear 获得年的部分 *

  • @param date 日期
  • @return 返回年份

func IsLeapYear

func IsLeapYear(dateTime time.Time) bool

IsLeapYear 判断是否是闰年 *

  • @param dateTime 日期
  • @return true:是闰年,false:不是闰年

func IsSameDay

func IsSameDay(date1, date2 time.Time) bool

IsSameDay 判断两个日期是否为同一天 *

  • @param date1 日期1
  • @param date2 日期2
  • @return true:是同一天,false:不是同一天

func IsSameMonth

func IsSameMonth(date1, date2 time.Time) bool

IsSameMonth 判断两个日期是否为同一月 *

  • @param date1 日期1
  • @param date2 日期2
  • @return true:是同一月,false:不是同一月

func LastWeek

func LastWeek() (time.Time, error)

LastWeek 上周 *

  • @return 上周

func LeapYear

func LeapYear(year int) bool

LeapYear 判断是否为闰年 *

  • @param year 年份
  • @return 闰年返回true 否则返回false

func LengthOfMonth

func LengthOfMonth(dateTime time.Time) int

LengthOfMonth 获取指定日期的月份的天数 *

  • @param dateTime 日期
  • @return 指定日期的月份的天数

func LengthOfYear

func LengthOfYear(dateTime time.Time) int

LengthOfYear 获取指定日期的年份的天数 *

  • @param dateTime 日期
  • @return 指定日期的年份的天数

func MillisecondOfToStr

func MillisecondOfToStr(timeMillis int64) string

MillisecondOfToStr 毫秒时间戳转字符串 *

  • @param timeMillis 时间戳,毫秒数
  • @return "yyyy-MM-dd HH:mm:ss" 格式字符串

func NextWeek

func NextWeek() (time.Time, error)

NextWeek 下周 *

  • @return 下周

func Now

func Now() string

Now 当前时间,格式 yyyy-MM-dd HH:mm:ss *

  • @return 当前时间的标准形式字符串,格式 yyyy-MM-dd HH:mm:ss

func OffSet

func OffSet(dateTime time.Time, timeUnit TimeUnit, offset int) (time.Time, error)

OffSet 获取指定日期偏移指定时间后的时间,生成的偏移日期不影响原日期 *

  • @param dateTime 基准日期
  • @param timeUnit 偏移的粒度大小(秒、分、小时、天、周) dateKit下的TimeSeconds、TimeMinute、TimeHour、TimeDay、TimeWeek
  • @param offset 偏移量,正数为向后偏移,负数为向前偏移
  • @return 偏移后的日期,错误

func OffsetDay

func OffsetDay(dateTime time.Time, offset int) (time.Time, error)

OffsetDay 偏移天 *

  • @param date 日期
  • @param offset 偏移天数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetHour

func OffsetHour(dateTime time.Time, offset int) (time.Time, error)

OffsetHour 偏移小时 *

  • @param date 日期
  • @param offset 偏移小时数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetMillisecond

func OffsetMillisecond(dateTime time.Time, offset int) (time.Time, error)

OffsetMillisecond 偏移毫秒数 *

  • @param date 日期
  • @param offset 偏移毫秒数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetMinute

func OffsetMinute(dateTime time.Time, offset int) (time.Time, error)

OffsetMinute 偏移分钟 *

  • @param date 日期
  • @param offset 偏移分钟数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetMonth

func OffsetMonth(dateTime time.Time, offset int) (time.Time, error)

OffsetMonth 偏移月 *

  • @param date 日期
  • @param offset 偏移月数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetSecond

func OffsetSecond(dateTime time.Time, offset int) (time.Time, error)

OffsetSecond 偏移秒数 *

  • @param date 日期
  • @param offset 偏移秒数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetWeek

func OffsetWeek(dateTime time.Time, offset int) (time.Time, error)

OffsetWeek 偏移周 *

  • @param date 日期
  • @param offset 偏移周数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func OffsetYear

func OffsetYear(dateTime time.Time, offset int) (time.Time, error)

OffsetYear 偏移年 *

  • @param date 日期
  • @param offset 偏移年数,正数向未来偏移,负数向历史偏移
  • @return 偏移后的日期

func ParseDate

func ParseDate(str string) time.Time

ParseDate 日期时间字符串转time类型 *

  • @param str 日期时间字符串 yyyy-MM-dd
  • @return 返回时间类型数据

func ParseDateTime

func ParseDateTime(str string) time.Time

ParseDateTime 日期时间字符串转time类型 *

  • @param str 日期时间字符串 yyyy-MM-dd HH:mm:ss
  • @return 返回时间类型数据

func Quarter

func Quarter(dateTime time.Time) string

Quarter 获得指定日期所属季度,从1开始计数 公历形式的划分3-5为春 *

  • @param dateTime 日期
  • @return 返回第几个季度 1:春、2:夏、3:秋、4:冬

func SecondOfToStr

func SecondOfToStr(timeSecond int64) string

SecondOfToStr 秒·时间戳转换为字符串 *

  • @param timeSecond 时间戳,秒数
  • @return "yyyy-MM-dd HH:mm:ss" 格式字符串

func SpendMs

func SpendMs(preTime int64) int64

SpendMs 计时,常用于记录某段代码的执行时间,单位:毫秒 *

  • @param preTime 之前记录的时间
  • @return 两次记录时间的差值,单位:毫秒

func SpendNt

func SpendNt(preTime int64) int64

SpendNt 计时,常用于记录某段代码的执行时间,单位:纳秒 *

  • @param preTime 之前记录的时间
  • @return 两次记录时间的差值,单位:纳秒

func Today

func Today() string

Today 获取当前日期,格式 yyyy-MM-dd *

  • @return 当前时间的标准形式字符串,格式 yyyy-MM-dd

func Tomorrow

func Tomorrow() (time.Time, error)

Tomorrow 明天 *

  • @return 明天

func Yesterday

func Yesterday() (time.Time, error)

Yesterday 昨天 *

  • @return 昨天

Types

type TimeUnit

type TimeUnit string

Jump to

Keyboard shortcuts

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