4
Days between two dates
source link: https://yourbasic.org/golang/days-between-dates/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Days between two dates
yourbasic.org/golang
func main() {
// The leap year 2016 had 366 days.
t1 := Date(2016, 1, 1)
t2 := Date(2017, 1, 1)
days := t2.Sub(t1).Hours() / 24
fmt.Println(days) // 366
}
func Date(year, month, day int) time.Time {
return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
}
Share:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK