Here, We are going to learn about how to get current time in go. What function will be used to get current time with program in go.
We will use time.Now() function of time package to get current time in go.
Function prototype:
func Now() Time
Return type:
Now() function of time package returns the current local time.
Example:
t := time.Now()
Program:
package main
import (
"fmt"
"time"
)
func main() {
curr_time := time.Now()
fmt.Println("Current time: ", curr_time)
}
Output:
Current time: 2020-05-29 13:24:43.750084 +0530 IST m=+0.000089951
Program:
package main
import (
"fmt"
"time"
)
func main() {
curr_time := time.Now()
f := curr_time.Format("01-02-2006 15:04:05")
fmt.Println("Current time: ", f)
}
Output:
Current time: 05-29-2020 13:28:10
To learn more about golang, You can refer given below link:
https://techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/ https://golang.org/pkg/