Skip to content

Instantly share code, notes, and snippets.

@saniyathossain
Forked from retgits/main.go
Created October 25, 2020 18:43
Show Gist options
  • Save saniyathossain/0da74be6cbd10d95348ca487557fc8b1 to your computer and use it in GitHub Desktop.
Save saniyathossain/0da74be6cbd10d95348ca487557fc8b1 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