How to Format Current Time in a yyyyMMddHHmmss Format in Go
Jay Singh
Feb 02, 2024
Go
Go DateTime

Datetime
is a type that encapsulates the attributes of a date and time at a certain point in time. Datetime
can be found in the time package in Go.
The time
package includes all of the functionality required for telling, measuring, and displaying the time. The time
package also contains the fundamental techniques for formatting, parsing, displaying, and manipulating dates and times.
Time is any variable type or field in a struct that holds time as a value. Time is a unit of measurement that represents a moment in time with millisecond precision.
Format Current Time in a yyyyMMddHHmmss
Format in Go
package main
import (
"fmt"
"time"
)
func main() {
currentTime := time.Now()
fmt.Printf("Current time is : %v\n", currentTime)
}
Output:
Current time is : 2023-11-16 08:37:19 +0000 UTC m=+0.000028927
The following is a basic example of RFC3339-compliant
time formatting with the associated layout constant.
package main
import (
"fmt"
"time"
)
func main() {
current_time := time.Now()
fmt.Println("Current time: ", current_time.Format(time.RFC3339))
}
Output:
Current time: 2023-11-16T08:37:19Z
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe