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 183 views
1 answer 214 views
1 answer 259 views
2 answers 229 views
1 answer 248 views
1 answer 167 views
1 answer 169 views
169 views asked Aug 13, 2020 by avibootz
...