0

I have this string date value

let stringDate = 2018-06-10T13:57:23.232+0000

the string date format will always be the same and I want to have output similar to one of these

6 year, 3 month, 1 day
or
3 month, 20 days
or
1 day

Basically I'm comparing the stringDate with current date and display how far they are apart from each other.

I'm able to get the date from string using this

    let dateFormatter = DateFormatter()
    var dateFromString: Date?
    dateFormatter.timeZone = NSTimeZone.local
    dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
    if let dateReturn = dateFormatter.date(from: stringDate) {
        dateFromString = dateReturn
    }

but I'm stuck on how to get the custom input like above. Thank you for helping me

KevinVuD
  • 581
  • 2
  • 5
  • 25
  • 1
    Check out this thread https://stackoverflow.com/questions/42294864/difference-between-2-dates-in-weeks-and-days-using-swift-3-and-xcode-8 – Satish Jun 21 '18 at 09:22
  • 3
    Possible duplicate of [Difference between 2 dates in weeks and days using swift 3 and xcode 8](https://stackoverflow.com/questions/42294864/difference-between-2-dates-in-weeks-and-days-using-swift-3-and-xcode-8) – user28434'mstep Jun 21 '18 at 09:23
  • Thank you very much – KevinVuD Jun 21 '18 at 09:26

0 Answers0