Created
August 22, 2017 18:26
-
-
Save martincalvert/2713bd35fd355e0773c60961950a8b27 to your computer and use it in GitHub Desktop.
Swift Difference Between Dates
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
//: Playground - noun: a place where people can play | |
import Foundation | |
let now = Date() | |
let future = Date(timeIntervalSinceNow: TimeInterval(1000000)) | |
let currentCalendar = Calendar.current | |
let calendarScale: Set<Calendar.Component> = [.day, .hour, .minute] | |
let difference = currentCalendar.dateComponents(calendarScale, from: now, to: future) | |
print("Days: \(difference.day!) Hours: \(difference.hour!) Seconds: \(difference.minute!)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment