Skip to content

Instantly share code, notes, and snippets.

@quyen91
Forked from hosszukalman/last_day_of_month.go
Created March 12, 2020 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quyen91/347ade6c368b3868fb1af57d888d0d5f to your computer and use it in GitHub Desktop.
Save quyen91/347ade6c368b3868fb1af57d888d0d5f to your computer and use it in GitHub Desktop.
Get the last day of the actual month in Golang
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
year, month, _ := now.Date()
endOfLastMonth := time.Date(year, month, 0, 0, 0, 0, 0, now.Location())
fmt.Printf("End of the last month: %s\n", endOfLastMonth)
firstDayOfThisMonth := time.Date(year, month, 1, 0, 0, 0, 0, now.Location())
fmt.Printf("The fist day of the actual month: %s\n", firstDayOfThisMonth)
endOfThisMonth := time.Date(year, month+1, 0, 0, 0, 0, 0, now.Location())
fmt.Printf("The end of this month: %s\n", endOfThisMonth)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment