Snippets Collections
let age = calcAge(birthday: "789089362000") // pass timeStamp in mili seconds
print("Age = \(age)")

func calcAge(birthday: String) -> Int {
    let seconds = (Int(birthday)!/1000) as NSNumber?
    let timeStampDate = Date(timeIntervalSince1970: seconds!.doubleValue)
    let calendar: NSCalendar! = NSCalendar(calendarIdentifier: .gregorian)
    let now = Date()
    let calcAge = calendar.components(.year, from: timeStampDate, to: now, options: [])
    let age = calcAge.year
    return age!

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension