Last active
March 21, 2018 18:59
-
-
Save vialyx/53c18e4c368db37785c784e7a330c8b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let dateComponentsFormatter = DateComponentsFormatter() | |
dateComponentsFormatter.unitsStyle = .full | |
dateComponentsFormatter.includesApproximationPhrase = true | |
dateComponentsFormatter.includesTimeRemainingPhrase = true | |
dateComponentsFormatter.allowedUnits = [.minute, .hour] | |
let timeIntervalInPast: TimeInterval = -3666 | |
let nowDate = Date() | |
let pastDate = nowDate.addingTimeInterval(timeIntervalInPast) | |
guard let formattedString = dateComponentsFormatter.string(from: pastDate, to: nowDate) else { fatalError() } | |
print("Remaining time: \(formattedString)") | |
// Remaining time: About 1 hour, 1 minute remaining |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment