datetime

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

日期时间工具包

工具加载

import (
	"github.com/cnlesscode/gotool/datetime"
)

TimeStampToDatatime(时间戳 int64) string

函数功能 : 时间戳转日期时间 返回格式 : 字符串形式的日期时间

fmt.Printf("%v", datetime.TimeStampToDatatime(1658997290))
// 2022-07-28 16:34:50

TimeStampToDatatimeSlice(时间戳 int64) []string

函数功能 : 时间戳转日期时间切片形式 返回格式 : 字符串切片

fmt.Printf("%v", datetime.TimeStampToDatatimeSlice(1658997290))
// [2022 07 28 16 34 50]

DateTimeToTimeStamp(日期时间 string) int64

函数功能 : 日期时间转时间戳 返回格式 : 时间戳 int64

fmt.Printf("%v\n", datetime.DateTimeToTimeStamp("2022-07-28 16:34:50"))
// 1658997290

FormatPastTime(时间戳 int64) (int, string, string)

函数功能 : 获取过去时间并格式化 返回格式 : 时间差, 过去时间 [ 英文 ], 过去时间 [ 中文 ]

func main() {
	timeDifference, strEn, strZh := datetime.FormatPastTime(1660707752 - 3600)
	fmt.Printf("timeDifference: %v\n", timeDifference)
	fmt.Printf("strEn: %v\n", strEn)
	fmt.Printf("strZh: %v\n", strZh)
}
// 1小时前 || ** 天前 || *** 分钟前 ...

CountDaysOfAMonth(某年某月 string) (int, error)

函数功能 : 计算某年某月天数 返回格式 : 天数, 错误

func main() {
	days, err := datetime.CountDaysOfAMonth("200402")
	if err == nil {
		fmt.Printf("days: %v\n", days)
	} else {
		fmt.Printf("err.Error(): %v\n", err.Error())
	}
	// 29
}

IsLeapYear(年份 int) bool

函数功能 : 判断某年是否为闰年 返回格式 : boolean

fmt.Printf("datetime.IsLeapYear(2000): %v\n", datetime.IsLeapYear(2000)) // true
fmt.Printf("datetime.IsLeapYear(2001): %v\n", datetime.IsLeapYear(2001)) // false

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountDaysOfAMonth

func CountDaysOfAMonth(yearAndMonth string) (int, error)

Count Days Of A Month

func DateTimeToTimeStamp

func DateTimeToTimeStamp(datetime string) int64

Date time to time stamp

func FormatPastTime

func FormatPastTime(pastTimeStamp int64) (int, string, string)

Calculate past time

func IsLeapYear

func IsLeapYear(year int) bool

Is Leap Year

func TimeStampToDatatime

func TimeStampToDatatime(timeStamp int64) string

Time stamp to date time

func TimeStampToDatatimeSlice

func TimeStampToDatatimeSlice(timeStamp int64) []string

Time stamp to slice [] string

Types

This section is empty.

Jump to

Keyboard shortcuts

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