Created
November 9, 2021 14:10
-
-
Save dimkagithub/04f33c54f0d2aa73ade60a191f0cd604 to your computer and use it in GitHub Desktop.
Time only comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func checkTime() -> Bool { | |
let dateFormatter: DateFormatter = DateFormatter() | |
dateFormatter.timeZone = TimeZone(abbreviation: "PKT") | |
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | |
let timeslot = "2021-11-09 16:00:00" | |
let currentDate = Date() | |
let date: Date = dateFormatter.date(from: timeslot)! | |
let currentTime = 60 * Calendar.current.component(.hour, from: currentDate) + Calendar.current.component(.minute, from: currentDate) + (Calendar.current.component(.second, from: currentDate) / 60) | |
let time = 60 * Calendar.current.component(.hour, from: date) + Calendar.current.component(.minute, from: date) + (Calendar.current.component(.second, from: date) / 60) | |
if currentTime >= time { | |
return true | |
} else { | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment