I am engaged on an software with a timer calculating the distinction in seconds between the 2 date objects.
Nonetheless i’ve skilled a bug IF the consumer adjustments present time in settings, it impacts the Date() object… I would really like to have the ability to get the precise time in UTC as a substitute of getting the time of the cellphone. I’d like to get the precise time right here irrespective of how the time is configured in settings…. Is that this attainable in any approach? In fact i might discover an API for getting the time however I want to do it in swift utilizing inner APIs whereas software just isn’t linked to the web.
var calendar = Calendar.present
if let timeZone = TimeZone(abbreviation: "UTC") {
calendar.timeZone = timeZone
let timeDiffrence = calendar.dateComponents([.minute], from: Date()).minute ?? 0
if timeDiffrence >= 10 || timeDiffrence <= -10 {
return false
} else {
return true
}
} else {
return true
}