Answer the question
In order to leave comments, you need to log in
Can you clarify the situation with typing in Go?
I started learning Golang, along the way deciding to write a generator to output dates sequentially. On the example of the standard lib time, the following script turned out
package main
import (
"fmt"
"time"
)
func main() {
date := time.Date(2020,1,1,12,0,0,0,time.UTC)
var days time.Duration = 32
var d *time.Duration = &days
var start time.Duration = 0
var s *time.Duration = &start
for *s = 0; *s < *d; *s++ {
res := date.Add(time.Hour * 24 * *s)
fmt.Println(res.Format("2006-01-02"))
}
}
Answer the question
In order to leave comments, you need to log in
Here is the correct option
package main
import (
"fmt"
"time"
)
func main() {
date := time.Date(2020, 1, 1, 12, 0, 0, 0, time.UTC)
var days int = 32
var start int = 0
for s := start; s < days; s++ {
res := date.Add(time.Duration(s) * time.Hour * 24)
format := res.Format("2006-01-02")
fmt.Println(format)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question