In Go language, time packages supplies functionality for determining as well as viewing time. The ParseError.Error() function in Go language is used to output the string description of a ParseError. Moreover, this function is defined under the time package. Here, you need to import “time” package in order to use these functions.
Syntax:
func (e *ParseError) Error() string
Here, “e” is the pointer to ParseError, And ParseError is used to explain a problem that parses a time string.
Return Value: It returns the string representation of a ParseError.
Example 1:
// Golang program to illustrate the usage of // time.ParseError() function // Including main package package main // Importing fmt and time import "fmt"
import "time"
// Calling main func main() { // Declaring a struct
// type ParseError
// with its values
error := time .ParseError{
Value: "1122020" ,
Message: " There is an error!" ,
}
// Calling Error method
// and printing string
// representation of ParseError
fmt.Println(error.Error())
} |
Output:
parsing time "1122020" There is an error!
Here, the string representation of Value and Message in struct type ParseError is returned.
Example 2:
// Golang program to illustrate the usage of // time.ParseError() function // Including main package package main // Importing fmt and time import "fmt"
import "time"
// Calling main func main() { // Declaring a struct
// type ParseError
// with its values
error := time .ParseError{
Layout: "2001 12 01" ,
Value: "11:34:09" ,
ValueElem: "11" ,
Message: " An error occurred!" ,
}
// Calling Error method
// and printing string
// representation of ParseError
fmt.Println(error.Error())
} |
Output:
parsing time "11:34:09" An error occurred!
It is the same as the above example but here more values are used in the ParseError struct type.