-1

I am trying to get the number of SECONDS between two Dates. for an example having a date like this:

let savedDate = Jun 25, 2018 at 12:48:09 AM -> (just printed as example date)
let currentDate = Date()

Can anyone help me understand how to find the number of second passed as a Double preferably?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rick C
  • 29
  • 1
  • 5

1 Answers1

2

Date#timeIntervalSince(_:) is probably what you're looking for.

Playground Example...

I modified the format so it would parse, but the basic concept works.

let formatter = DateFormatter()
formatter.dateFormat = "MMM dd, yyyy hh:mm:ss a"
let date = formatter.date(from: "Jun 25, 2018 12:48:09 AM")
if let date = date {
    Date().timeIntervalSince(date)
}

Will output

29793.5867500305
Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366