Created
August 27, 2021 02:37
-
-
Save linw1995/9b2e7d53dcf4706279341bb3597dda01 to your computer and use it in GitHub Desktop.
get begin time and end time in Golang.
This file contains 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() | |
fmt.Println( | |
now.Truncate(time.Hour*24), | |
now.Truncate(time.Hour*24).Add(time.Hour*23+time.Minute*59+time.Second*59), | |
now, | |
) | |
} |
This file contains 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() | |
fmt.Println( | |
now.AddDate(0, 0, 1-now.Day()).Truncate(time.Hour*24), | |
now.AddDate(0, 1, -now.Day()).Truncate(time.Hour*24).Add(time.Hour*23+time.Minute*59+time.Second*59), | |
now, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment