How to get the current date and time in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "time"
)

func main() {
    currentTime := time.Now()
    
    fmt.Println("Current Date and Time:", currentTime)
    
    datetimeString := currentTime.Format("2006-01-02 15:04:05")
 
    fmt.Println("Current datetime:", datetimeString)
}

 
 
/*
run:
 
Current Date and Time: 2025-05-05 19:43:14.818283371 +0000 UTC m=+0.000032651
Current datetime: 2025-05-05 19:43:14
 
*/

 



answered May 5, 2025 by avibootz

Related questions

1 answer 87 views
1 answer 219 views
219 views asked Aug 26, 2020 by avibootz
1 answer 103 views
1 answer 97 views
1 answer 148 views
...