The Go implementation compares the time size
- 2020-05-27 05:52:16
- OfStack
First, format the current time into a string in the same format, then use the Before, After, Equal methods of time.
time1 := "2015-03-20 08:50:29"
time2 := "2015-03-21 09:04:25"
// First, format the time string into the same time type
t1, err := time.Parse("2006-01-02 15:04:05", time1)
t2, err := time.Parse("2006-01-02 15:04:05", time2)
if err == nil && t1.Before(t2) {
// Processing logic
fmt.Println("true")
}
Here is oneline's Demo, which can be modified and run online. https: / / play. golang. org/p/oRJ_1 - DE4l
The above is the entire content of this article, I hope you can enjoy it.