belongs to collection: Golang Date & Time Programs
Golang program to get Formatted Date and Time
package main import "fmt" import "time" func main() { dtobj := time.Now() // MM-DD-YYYY format fmt.Println(dtobj.Format("01-02-2006")) // MM-DD-YYYY HH:MM:SS format fmt.Println(dtobj.Format("01-02-2006 15:04:05")) // MM-DD-YYYY HH:MM:SS DAY format fmt.Println(dtobj.Format("01-02-2006 15:04:05 Mon")) // MM-DD-YYYY HH:MM:SS DAY (full) format fmt.Println(dtobj.Format("01-02-2006 15:04:05 Monday")) // MM-DD-YYYY HH:MM:SS Micro Seconds format fmt.Println(dtobj.Format("01-02-2006 15:04:05.000000")) // MM-DD-YYYY HH:MM:SS Nano Seconds format fmt.Println(dtobj.Format("01-02-2006 15:04:05.000000000")) }
Output:
03-21-2021 03-21-2021 05:57:59 03-21-2021 05:57:59 Sun 03-21-2021 05:57:59 Sunday 03-21-2021 05:57:59.116203 03-21-2021 05:57:59.116203254
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer