Created
October 24, 2019 16:36
-
-
Save hosszukalman/8fd4bb046f4a20d55f4723776d6cc964 to your computer and use it in GitHub Desktop.
Get the last day of the actual month in Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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