Skip to content

Instantly share code, notes, and snippets.

@retgits
Created August 27, 2018 04:25
Show Gist options
  • Save retgits/903106b03304a8d6f5b62cd2e1a8defd to your computer and use it in GitHub Desktop.
Save retgits/903106b03304a8d6f5b62cd2e1a8defd to your computer and use it in GitHub Desktop.
Get the current date in Go
// Original source: https://gistpages.com/posts/go-lang-get-current-date
// Go playground: https://play.golang.org/p/gBO8rdKI6UF
// time.Format should use the layout, Mon Jan 2 15:04:05 MST 2006 to show the pattern
package main
import (
"fmt"
"time"
)
func main() {
current_time := time.Now().Local()
fmt.Println("The Current time is ", current_time.Format("2006-01-02"))
current_time = time.Now().UTC()
fmt.Println("The Current time is ", current_time.Format("2006-01-02 MST"))
}
// $ go run main.go
// The Current time is 2009-11-10
// The Current time is 2009-11-10 UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment