Skip to content

Instantly share code, notes, and snippets.

@dimkagithub
Created November 9, 2021 14:10
Show Gist options
  • Save dimkagithub/04f33c54f0d2aa73ade60a191f0cd604 to your computer and use it in GitHub Desktop.
Save dimkagithub/04f33c54f0d2aa73ade60a191f0cd604 to your computer and use it in GitHub Desktop.
Time only comparison
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