Q:

Golang program to get Formatted Date and Time

belongs to collection: Golang Date & Time Programs

0

Golang program to get Formatted Date and Time

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Golang Date & Time Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Golang program to print current date-time in diffe... >>
<< Golang program to get current date and time...