0

I'm trying to get the time in milliseconds since a certain date. Here is my code:

startTime = NSDate.timeIntervalSinceReferenceDate()
startDate = NSDate()

let dateComponents = NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitSecond | NSCalendarUnit.CalendarUnitNanosecond, fromDate: startDate, toDate: NSDate(), options: nil)

println("\(dateComponents.seconds)")

(I did seconds to make it easier, but in the actual thing I will need milliseconds.) It gives me seconds, but after 59, it goes back to 0. (It's a timer. If you want I can show that code too, but I thought it wouldn't be necessary.)

How can I get it to show milliseconds and go all the way - I don't want it to start over?

Update

I tried the following:

let milliseconds : Double = [startDate .timeIntervalSinceNow] * -1000.0

It then says to put a comma after startDate. After I do that, I get an error:

Could not find member 'timeIntervalSinceNow'

Jessica
  • 9,379
  • 14
  • 65
  • 136
  • I tried the following: let milliseconds : Double = [startDate .timeIntervalSinceNow] * -1000.0 It then says to put a comma after startDate. After I do that, I get an error: Could not find member 'timeIntervalSinceNow' – Jessica Aug 27 '15 at 20:32
  • The above code is Objective-C, see in the answers of the duplicate question, I recently put an answer like the above but in Swift. – Victor Sigler Aug 27 '15 at 20:41
  • Thanks! I'll upvote your answer! – Jessica Aug 27 '15 at 20:51

0 Answers0