From 90f69f2c8147360fbbf17e0c3e444f60ac81cb0b Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Thu, 23 Dec 2021 14:24:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B7=E4=BD=93=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E8=BD=AC=E6=97=B6=E9=97=B4=E6=88=B3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- time.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/time.go b/time.go index a0af841..0607207 100755 --- a/time.go +++ b/time.go @@ -1,6 +1,7 @@ package helper import ( + "git.tetele.net/tgo/helper" "strconv" "time" ) @@ -20,7 +21,7 @@ func FormatDate(str string) string { return time.Unix(date, 0).Format("2006-01-02") } -//获取当天开始时间戳 +// 获取当天开始时间戳 func GetTodayStartTimeStamp() int64 { var reserveTime time.Time @@ -31,7 +32,7 @@ func GetTodayStartTimeStamp() int64 { return reserveTime.Unix() } -//获取本周开始时间戳 +// 获取本周开始时间戳 func GetWeekStartTimeStamp() int64 { var reserveTime time.Time @@ -50,7 +51,7 @@ func GetWeekStartTimeStamp() int64 { return reserveTime.Unix() } -//获取当月开始时间戳 +// 获取当月开始时间戳 func GetMonthStartTimeStamp() int64 { var reserveTime time.Time @@ -79,3 +80,12 @@ func RFC3339ToCSTLayout(value string) (string, error) { return ts.In(cst).Format("2006-01-02 15:04:05"), nil } + +// 具体日期时间转时间戳 +func DatetimeToUnix(value string) int64 { + loc, _ := time.LoadLocation("Asia/Shanghai") + + reserveTime, _ := time.ParseInLocation("2006-01-02 15:04:05", helper.ToStr(value), loc) + + return reserveTime.Unix() +}