How to get the first day of current month in Go

1 Answer

0 votes
package main
    
import (
    "fmt"
    "time"
)

func main() {
    now := time.Now()
    currentYear, currentMonth, _ := now.Date()

    firstDayOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, now.Location())

    fmt.Println(firstDayOfMonth)
    fmt.Println(firstDayOfMonth.Day())
}
 
 
   
   
/*
run:
   
2020-08-01 00:00:00 +0000 UTC
1
   
*/

 



answered Aug 27, 2020 by avibootz

Related questions

1 answer 255 views
1 answer 304 views
1 answer 360 views
2 answers 338 views
1 answer 325 views
1 answer 238 views
1 answer 254 views
254 views asked Aug 13, 2020 by avibootz
...