How to get hours difference between two dates in Go

1 Answer

0 votes
package main
    
import (
    "fmt"
    "time"
)
    
func main() {
    dt1 := time.Date(2020, 8, 16, 13, 42, 26, 3216532101, time.UTC)
    dt2 := time.Date(2020, 8, 15, 13, 42, 26, 3216532101, time.UTC)
      
    diff := dt1.Sub(dt2)
      
    hours := int(diff.Hours())
  
    fmt.Println(hours)
}
   
   
 
/*
run:
  
24
  
*/

 



answered Aug 16, 2020 by avibootz
edited Aug 16, 2020 by avibootz

Related questions

1 answer 109 views
1 answer 182 views
2 answers 143 views
2 answers 206 views
1 answer 185 views
...