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! }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter