If you need to convert Time
to a String
in Go, then you can do one of the following:
Option 1 – Using time.Now
1
2
3
4
5
6
7
8
9
10
11
|
package main
import (
"fmt"
"time"
)
func main() {
currentTime := time.Now()
fmt.Println("Time: ", currentTime.String())
}
|
Option 2 – Using time.Time.String()
1
2
3
4
5
6
7
8
9
10
11
12
|
package main
import (
"fmt"
"time"
)
func main() {
Time := time.Date(2022, 03, 28, 03, 50, 16, 0, time.UTC)
t := Time.String()
fmt.Printf("Time without the nano seconds: %v\n", t)
}
|