Browse Source

增加具体日期转时间戳函数

master
lijianbin 2 years ago
parent
commit
90f69f2c81
1 changed files with 13 additions and 3 deletions
  1. +13
    -3
      time.go

+ 13
- 3
time.go View File

@ -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()
}

Loading…
Cancel
Save