Browse Source

修改获取本地时间

master v0.3.2
guzeng 2 years ago
parent
commit
be3c84d62c
2 changed files with 18 additions and 9 deletions
  1. +4
    -4
      time.go
  2. +14
    -5
      time_test.go

+ 4
- 4
time.go View File

@ -24,10 +24,10 @@ func FormatDate(str string) string {
func GetTodayStartTimeStamp() int64 { func GetTodayStartTimeStamp() int64 {
var reserveTime time.Time var reserveTime time.Time
loc, _ := time.LoadLocation("Asia/Shanghai")
// loc, _ := time.LoadLocation(time.Location.String())
date := time.Now().Format("2006-01-02") date := time.Now().Format("2006-01-02")
reserveTime, _ = time.ParseInLocation("2006-01-02", date, loc)
reserveTime, _ = time.ParseInLocation("2006-01-02", date, time.Local)
return reserveTime.Unix() return reserveTime.Unix()
} }
@ -35,10 +35,10 @@ func GetTodayStartTimeStamp() int64 {
func GetTodayEndTimeStamp() int64 { func GetTodayEndTimeStamp() int64 {
var reserveTime time.Time var reserveTime time.Time
loc, _ := time.LoadLocation("Asia/Shanghai")
// loc, _ := time.LoadLocation("Asia/Shanghai")
date := time.Now().Format("2006-01-02") date := time.Now().Format("2006-01-02")
reserveTime, _ = time.ParseInLocation("2006-01-02 15:04:05", date+" 23:59:59", loc)
reserveTime, _ = time.ParseInLocation("2006-01-02 15:04:05", date+" 23:59:59", time.Local)
return reserveTime.Unix() return reserveTime.Unix()
} }


+ 14
- 5
time_test.go View File

@ -19,10 +19,19 @@ import (
// func Test_GetToadyStartTimeStamp(t *testing.T) { // func Test_GetToadyStartTimeStamp(t *testing.T) {
// t.Log(GetMonthStartTimeStamp()) // t.Log(GetMonthStartTimeStamp())
// } // }
func Test_RFC3339ToCSTLayout(t *testing.T) {
cur := "2018-06-08T10:34:56+08:00"
// func Test_RFC3339ToCSTLayout(t *testing.T) {
// cur := "2018-06-08T10:34:56+08:00"
// ret, err := RFC3339ToCSTLayout(cur)
// t.Log(ret)
// t.Log(err)
// }
func Test_GetTodayStartTimeStamp(t *testing.T) {
for i := 0; i < 1000; i++ {
ret := GetTodayEndTimeStamp()
t.Log(ret)
}
ret, err := RFC3339ToCSTLayout(cur)
t.Log(ret)
t.Log(err)
} }

Loading…
Cancel
Save