Created
August 27, 2018 04:25
-
-
Save retgits/903106b03304a8d6f5b62cd2e1a8defd to your computer and use it in GitHub Desktop.
Get the current date in Go
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
// 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