time.Time.Equal() Function in Golang With Examples
In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Equal() function in Go language is used to check if the stated times “t” and “u” represents identical time instant or not. And two times located in different locations can even be equal. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.
Syntax:
func (t Time) Equal(u Time) bool
Here, “t” and “u” are the stated time.
Return Value: It returns true if the stated times are equal else it returns false.
Example 1:
package main
import "fmt"
import "time"
func main() {
t := time .Date(2020, 3, 2, 12, 14, 0, 0, time .UTC)
u := time .Date(2020, 3, 1, 36, 14, 0, 0, time .UTC)
TimesequalOrnot := t.Equal(u)
fmt.Printf( "%v\n" , TimesequalOrnot)
}
|
Output:
true
Example 2:
package main
import "fmt"
import "time"
func main() {
t := time .Date(2020, 3, 2, 12,
14, 07, 0, time .UTC)
u := time .Date(2020, 3, 1, 36,
14, 0, 0, time .UTC)
TimesequalOrnot := t.Equal(u)
fmt.Printf( "%v\n" , TimesequalOrnot)
}
|
Output:
false
Last Updated :
21 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...