-2

I'm playing with swift. I want to show how many years/months/days has been passed since the specific date(NSdate).

If the specific date is 08/01/2016 and current date is 08/11/2016, it will show only "10day(s) has been passed". If the specific date is 08/11/2015, it will show "1year(s) 0 month(s) 0day(s)has been passed"

JessJ
  • 57
  • 9

1 Answers1

1

Do something like this. Use your dates in date1 and date2

let date1 = NSDate()
let date2 = NSDate()

let form = NSDateComponentsFormatter()
form.maximumUnitCount = 2
form.unitsStyle = .Full
form.allowedUnits = [.Year, .Month, .Day]
let s = form.stringFromDate(date1, toDate: date2)
Harsh
  • 2,852
  • 1
  • 13
  • 27