Created
July 11, 2020 19:33
-
-
Save dimohamdy/04e5e8a62ce06586c3e4a5348e370210 to your computer and use it in GitHub Desktop.
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
extension Date { | |
var timeAgo: String { | |
get { | |
let relativeDateFormatter = RelativeDateTimeFormatter() | |
//change these to get different formats | |
relativeDateFormatter.dateTimeStyle = .named | |
relativeDateFormatter.unitsStyle = .full | |
//you can know your loacal identifier here https://gist.github.com/jacobbubu/1836273 | |
relativeDateFormatter.locale = Locale(identifier: "ar_EG") | |
let relativeDate = relativeDateFormatter.localizedString(for: self, relativeTo: Date()) | |
return relativeDate.capitalized | |
} | |
} | |
} | |
let now = Date(timeIntervalSince1970: 1232434) | |
print(now.timeAgo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment