Skip to content

Instantly share code, notes, and snippets.

@dimohamdy
Created July 11, 2020 19:33
Show Gist options
  • Save dimohamdy/04e5e8a62ce06586c3e4a5348e370210 to your computer and use it in GitHub Desktop.
Save dimohamdy/04e5e8a62ce06586c3e4a5348e370210 to your computer and use it in GitHub Desktop.
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