How to get the difference between two times in Go

2 Answers

0 votes
package main
   
import (
    "fmt"
    "time"
)
   
func main() {
    t1 := time.Now()
    t2 := t1.Add(time.Second * 10)

    diff := t2.Sub(t1)
    fmt.Println(diff)
}
  
  

/*
run:
 
10s
 
*/

 



answered Aug 16, 2020 by avibootz
0 votes
package main
   
import (
    "fmt"
    "time"
)
   
func main() {
    t1 := time.Now()
    t2 := t1.Add(time.Second * 100)

    diff := t2.Sub(t1)
    fmt.Println(diff)
}
  
  

/*
run:
 
1m40s
 
*/

 



answered Aug 16, 2020 by avibootz
...