Skip to content

Instantly share code, notes, and snippets.

@jiaoyk
Forked from hosszukalman/last_day_of_month.go
Created September 30, 2024 07:12
Show Gist options
  • Save jiaoyk/efd9cd1e1df64241a02b1af23c6ee86e to your computer and use it in GitHub Desktop.
Save jiaoyk/efd9cd1e1df64241a02b1af23c6ee86e to your computer and use it in GitHub Desktop.

Revisions

  1. @hosszukalman hosszukalman created this gist Oct 24, 2019.
    20 changes: 20 additions & 0 deletions last_day_of_month.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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)

    }