-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeUse.go
95 lines (81 loc) · 1.85 KB
/
timeUse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"log"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type Foo struct {
Name string
Ports []int
Enabled bool
}
func main() {
//timeTick()
//timeParse()
//timeFormat()
fmt.Println(GetEndOfDay(time.Now()))
}
func GetEndOfDay(t time.Time) time.Time {
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Fatalf("util.GetEndOfDay load location: %+v", err)
}
y, m, d := t.In(loc).Date()
return time.Date(y, m, d, 23, 59, 59, 0, loc)
}
func timeFormat() {
t := time.Now()
fmt.Println(t.Format("2006.01.02 15:04"))
fmt.Println(t.UTC().Format("2006.01.02 15:04"))
}
func timeTick() {
t := time.NewTicker(5 * time.Second)
defer t.Stop()
fmt.Println(time.Now())
for {
select {
case <-t.C:
fmt.Println(time.Now())
}
}
}
func timeParse() {
a, err := time.Parse("2006-01-02T15:04:05Z07:00", "2019-02-01T15:35:12.326+08:00")
fmt.Println(a, err)
}
func TestTimeEqual(t *testing.T) {
t.Log(time.RFC3339)
assert := assert.New(t)
t1, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
assert.Nil(err)
t2, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
assert.Nil(err)
assert.Equal(t1, t2, "t1 == t2")
}
/*
func typeOfTime() {
t := time.Now()
fmt.Println(reflect.TypeOf(t))
latency := time.Since(t)
fmt.Println(reflect.TypeOf(latency))
fmt.Println(latency)
foo := Foo{Name: "gopher", Ports: []int{80, 443}, Enabled: true}
fmt.Printf("foo = %+v\n", foo)
}
func parseTime() {
value := "Thu, 05/19/11"
// value := "Thu, 05/19/11, 10:47PM"
// Writing down the way the standard time would look like formatted our way
layout := "Mon, 01/02/06, 03:04PM"
t, _ := time.Parse(layout, value)
fmt.Println(t)
}
func formatTime() {
// t := time.SecondsToLocalTime(1305861602)
// var t time.Time
// t.ZoneOffset = -4 * 60 * 60
// fmt.Println(t.Format("2006-01-02 15:04:05 -0700"))
}
*/