Reputation: 2019
I can't find an accurate answer, but all I want to do is:
I was using this code:
let date = Date(timeIntervalSince1970: TimeInterval(timeInMiliFromBackEnd/1000))
let interval = date.timeIntervalSince1970
let url = NSURL(string: "calshow:\(interval)")!
UIApplication.shared.openURL(url as URL)
The calendar app opens, however it opens in some random year (January 2066 @ 3pm).
Can anyone provide the swift 3 code for this?
Cheers~
Upvotes: 2
Views: 2047
Reputation: 131491
iOS Doesn't use timeIntervalSince1970
as it's "epoch date." You should use timeIntervalSinceReferenceDate
instead:
//Convert the time from the server into a Date object
let seconds = TimeInterval(timeInMiliFromBackEnd/1000)
let date = Date(timeIntervalSince1970: seconds)
//Convert the Date object into the number of seconds since the iOS "epoch date"
let interval = date.timeIntervalSinceReferenceDate
if let url = URL(string: "calshow:\(interval)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
(Code above updated to use newer open(_:options:completionHandler:)
method, as opposed to the now-deprecated openURL(_:)
method.)
Upvotes: 3