Browse Source

Merge branch 'master' of ssh://git.tetele.net:4001/tgo/helper

master v0.1.9
guzeng 3 years ago
parent
commit
c944b89b55
3 changed files with 46 additions and 0 deletions
  1. +1
    -0
      string_test.go
  2. +41
    -0
      time.go
  3. +4
    -0
      time_test.go

+ 1
- 0
string_test.go View File

@ -1,6 +1,7 @@
package helper
import (
"fmt"
"testing"
)


+ 41
- 0
time.go View File

@ -19,3 +19,44 @@ func FormatDate(str string) string {
}
return time.Unix(date, 0).Format("2006-01-02")
}
//获取当天开始时间戳
func GetTodayStartTimeStamp() int64{
var reserveTime time.Time
loc, _ := time.LoadLocation("Asia/Shanghai")
date := time.Now().Format("2006-01-02")
reserveTime,_ = time.ParseInLocation("2006-01-02",date,loc)
return reserveTime.Unix()
}
//获取本周开始时间戳
func GetWeekStartTimeStamp() int64{
var reserveTime time.Time
now := time.Now()
loc, _ := time.LoadLocation("Asia/Shanghai")
offset := int(time.Monday - now.Weekday())
if offset > 0 {
offset = -6
}
weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
weekMonday := weekStartDate.Format("2006-01-02")
reserveTime,_ = time.ParseInLocation("2006-01-02",weekMonday,loc)
return reserveTime.Unix()
}
//获取当月开始时间戳
func GetMonthStartTimeStamp() int64{
var reserveTime time.Time
loc, _ := time.LoadLocation("Asia/Shanghai")
date := time.Now().Format("2006-01")
reserveTime,_ = time.ParseInLocation("2006-01",date,loc)
return reserveTime.Unix()
}

+ 4
- 0
time_test.go View File

@ -15,3 +15,7 @@ func Test_FormatDate(t *testing.T) {
t.Log(ret.Unix())
t.Log(err)
}
func Test_GetToadyStartTimeStamp(t *testing.T){
t.Log(GetMonthStartTimeStamp())
}

Loading…
Cancel
Save