With the help of
Equal(), function we can compare the time as well as date but we are also going to use the
time.Now().Add() function for comparision.
Functions Used: These functions compares the times as seconds.
Before(temp)– This function is used to check if the given time is before the temporary time variable and return true if the time variable comes before the temporary time variable else false.
After(temp)– This function is used to check if given time is after the temporary time variable and return true if time variable comes after temporary time variable else false.
Equal(temp)– This function is used to check if given time is equal the temporary time variable and return true if time variable equals temporary time variable else false.
Example #1 : In this example we can see that by using
After() function, we are able to compare the dates by using these functions.
today before tomorrow: true tomorrow after today: true
Example #2 :
today is not tomorrow sameday is today today is sameday
- Different ways to compare Strings in Golang
- How to compare two slices of bytes in Golang?
- How to Compare Equality of Struct, Slice and Map in Golang?
- strings.Compare() Function in Golang with Examples
- Compare Println vs Printf in Golang with Examples
- How to compare Structs with the Different Values Assigned to Data Fields in Golang?
- Repeating a String for Specific Number of Times in Golang
- Zero value in Golang
- How to use Ellipsis (...) in Golang?
- How to copy a map to another map in Golang?
- Packages in Golang
- Using WaitGroup in Golang
- Closures in Golang
- Rune in Golang
- What is Regex in Golang?
- Methods With Same Name in Golang
- Recover in Golang
- Panic in Golang
- Encapsulation in Golang
- Strings in Golang
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.