The Go standard library does not include a strconv.ParseTime()
function. However, you can use the time.Parse()
function from the time
package to parse a string with a custom layout into a time.Time
value. Here's an example:
package main
import (
"fmt"
"time"
)
func main() {
layout := "2006-01-02 15:04:05" // Custom layout that matches your string format
str := "2022-12-31 23:59:59" // The string you want to parse
t, err := time.Parse(layout, str)
if err != nil {
fmt.Println("Error parsing time:", err)
return
}
fmt.Println("Parsed time:", t)
}
In this example, the layout pattern "2006-01-02 15:04:05"
represents the correct format for the given string "2022-12-31 23:59:59"
. The layout
parameter should be specified according to the layout of your input string.
The time.Parse()
function returns a time.Time
value and an error. If err
is not nil
, it means the parsing failed.