File tree Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 1
1
# timestampHelper
2
- small tool for convert timestamp to string or convert string to timestamp
2
+
3
+ Small tool for convert timestamp to string or convert string to timestamp.
4
+
5
+ ## Useage
6
+
7
+ ` > timehelper 2019-01-01 1546300800 `
8
+
9
+ timehelper [ formatted string date or timestamp] ...
10
+
11
+ ![ show] ( https://ws2.sinaimg.cn/large/006tNc79ly1fyzcyjyqwjj30qo02ugm5.jpg )
12
+
13
+ ##Warning
14
+
15
+ * formatted date string must be YYYY-MM-DD
16
+ * timestamp must only 10 bits, 13 bits must convert to 10 bits timestamp
Original file line number Diff line number Diff line change
1
+ module timehelper
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "strconv"
7
+ "time"
8
+ )
9
+
10
+ func main () {
11
+ list := os .Args
12
+ if len (list ) == 1 {
13
+ fmt .Println ("missing args" )
14
+ os .Exit (1 )
15
+ }
16
+ result := ""
17
+ for index , value := range list {
18
+ //filter script self
19
+ if index == 0 {
20
+ continue
21
+ }
22
+ //convert to int
23
+ intValue , err := strconv .Atoi (value )
24
+ //convert str to timestamp
25
+ if err != nil {
26
+ timeStamp , _ := time .Parse ("2006-01-02" , value )
27
+ result = strconv .FormatInt (timeStamp .Unix (), 10 )
28
+ } else {
29
+ //convert timestamp to str
30
+ tm := time .Unix (int64 (intValue ), 0 )
31
+ result = tm .Format ("2006-01-02 15:04:05" )
32
+ }
33
+ output := value + " => " + result
34
+ fmt .Println (output )
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments