time.ParseError.Error() Function in Golang With Examples
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:
package main
import "fmt"
import "time"
func main() {
error := time .ParseError{
Value: "1122020" ,
Message: " There is an error!" ,
}
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:
package main
import "fmt"
import "time"
func main() {
error := time .ParseError{
Layout: "2001 12 01" ,
Value: "11:34:09" ,
ValueElem: "11" ,
Message: " An error occurred!" ,
}
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.
Last Updated :
21 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...