For example, when you start the app, you may want to compare the current time with the time preset by the developer and perform the processing that suits the situation. (Processing A before what time, B after what time, etc.)
The .compare () method
can be used in such situations.
This time I will introduce this method!
if 'Current time'.compare('Time set here') == .orderedDescending {
//Process here
//.orderedDescending is after
}
if 'Current time'.compare('Time set here') == .orderedAscending {
//Process here
//.orderedAscending is before
}
If you write like this, it's OK!
The two times are compared by the .compare () method
to determine whether it is later or earlier.
Also, if you want to determine if both times are the same, use .orderedSame
.
please refer!
Recommended Posts