[Swift5] How to compare specific times to determine if it is before or after

Comparison of specific times

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!

Description 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

[Swift5] How to compare specific times to determine if it is before or after
Program to determine if it is a leap year
Get the type of an array element to determine if it is an array
If the parameter is an array, how to include it in Stopara's params.permit
How to execute processing before and after docker-entrypoint.sh
[Swift] If the support of the application is iOS 11 or later, it was not necessary to use Int and Int64 properly
[swift5] How to execute processing when tabBar is tapped
Library to check if it is an IPv4 format string