Jump to content

Last Friday of each month: Difference between revisions

m
→‎{{header|Go}}: Replace constant to make it clear how Friday is being chosen
(Add Nimrod)
m (→‎{{header|Go}}: Replace constant to make it clear how Friday is being chosen)
Line 433:
 
import (
"fmt"
"os"
"strconv"
"time"
)
 
func main() {
y := time.Now().Year()
if len(os.Args) == 2 {
if i, err := strconv.Atoi(os.Args[1]); err == nil {
y = i
}
}
}
}
for m := time.January; m <= time.December; m++ {
d := time.Date(y, m+1, 1, 0, 0, 0, 0, time.UTC).Add(-24 * time.Hour)
d = d.Add(-time.Duration((d.Weekday() + 27-time.Friday) % 7) * 24 * time.Hour)
fmt.Println(d.Format("2006-01-02"))
}
}
}</lang>
Output:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.