feat(Go-Tool):创建timed包相关时间操作工具,实现时间戳、时间格式化操作。创建timed测试类

This commit is contained in:
huangzj
2020-05-07 16:14:37 +08:00
parent d448fbad5e
commit 24c319a182
13 changed files with 554 additions and 1 deletions
+52
View File
@@ -0,0 +1,52 @@
/*
* @Author : huangzj
* @Time : 2020/5/7 9:20
* @Description 时间戳工具类
*/
package timed
import "time"
/*
* 获取当月月初的时间戳
*/
func GetNowMonthUnix() int64 {
now := time.Now()
month := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
return month.Unix()
}
/*
* 获取当天零时的时间戳
*/
func GetZeroHourUnix() int64 {
now := time.Now()
zeroHour := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
return zeroHour.Unix()
}
/*
* 获取当前时间戳
*/
func GetNowUnix() int64 {
return time.Now().Unix()
}
/*
* 获取当前小时时间戳
*/
func GetNowHourUnix() int64 {
now := time.Now()
hour := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location())
return hour.Unix()
}
/*
* 获取今年年初的时间戳
*/
func GetNowYearUnix() int64 {
now := time.Now()
tm := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
return tm.Unix()
}