Skip to content

Instantly share code, notes, and snippets.

@linw1995
Created August 27, 2021 02:37
Show Gist options
  • Save linw1995/9b2e7d53dcf4706279341bb3597dda01 to your computer and use it in GitHub Desktop.
Save linw1995/9b2e7d53dcf4706279341bb3597dda01 to your computer and use it in GitHub Desktop.
get begin time and end time in Golang.
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,
)
}
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,
)
}
@xvbnm48
Copy link

xvbnm48 commented Oct 28, 2022

thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment