Date diff
This commit is contained in:
parent
01518f6f9f
commit
8cd3a4517f
1
.gitignore
vendored
1
.gitignore
vendored
@ -39,3 +39,4 @@ my-md5/my-md5
|
|||||||
shadir/shadir
|
shadir/shadir
|
||||||
shadirconcurrent/shadirconcurrent
|
shadirconcurrent/shadirconcurrent
|
||||||
pinger/pinger
|
pinger/pinger
|
||||||
|
datediff/datediff
|
||||||
|
28
datediff/main.go
Normal file
28
datediff/main.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "log"
|
||||||
|
import "os"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) != 3 {
|
||||||
|
log.Fatalln("usage datediff <date1> <date2>")
|
||||||
|
}
|
||||||
|
|
||||||
|
FORMAT := "02/01/2006"
|
||||||
|
d1, err := time.ParseInLocation(FORMAT, os.Args[1], time.Local)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Invalid date 1", err)
|
||||||
|
}
|
||||||
|
d2, err := time.ParseInLocation(FORMAT, os.Args[2], time.Local)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Invalid date 2", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dur := d2.Sub(d1)
|
||||||
|
|
||||||
|
//fmt.Println(dur.String())
|
||||||
|
|
||||||
|
fmt.Println(int64(dur / (24 * time.Hour)))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user