Skip to content

Commit 2a37fca

Browse files
author
ligongxiang
committed
add code and binary programs
1 parent c559dd7 commit 2a37fca

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# 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

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module timehelper

main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

timehelper

1.97 MB
Binary file not shown.

0 commit comments

Comments
 (0)