Skip to content

How to Convert Time to String in Golang

If you need to convert Time to a String in Go, then you can do one of the following:

Option 1 – Using time.Now

package main import ( "fmt" "time" ) func main() { currentTime := time.Now() fmt.Println("Time: ", currentTime.String()) }
Code language: Go (go)

Option 2 – Using time.Time.String()

package main import ( "fmt" "time" ) func main() { Time := time.Date(2022, 03, 28, 03, 50, 16, , time.UTC) t := Time.String() fmt.Printf("Time without the nano seconds: %v\n", t) }
Code language: CSS (css)

See also  Forming Unique Array Combinations in Golang
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x