I would like that my app would show how much time has passed since some time mark, like Stopwatch. Should I used NSdate?
I've tried using
NSDate(timeIntervalSinceReferenceDate:_) and as parameter I wanted to chose
NSDate(timeIntervalSince1970: someTimeStamp) which is not allowed.
I also tried doing it manually, by converting
NSTimeInterval of current time to
Int like this:
var date = NSDate().timeIntervalSince1970 let time3 = Int(date) let time4 = Int(someTimeStamp) //NSTimeInterval in Epoch time let time5 = Double(time3 - time4) let time6 = NSDate(timeIntervalSinceReferenceDate: time5) //This is what I need
Although now I am not sure how to properly display
time6, I could do manually divide by 60 to get minutes and divide by 60 to get hours, but I am pretty sure there has to be simpler way to display how much time has passed since
NSTimeInterval (preferably in
mm format if below 60 minutes and in
hh:mm if above 60 minutes)
let elapsedTime = NSDate().timeIntervalSinceDate(DateYouWantToPassToGetInterval)
Note the () after the NSDate. The NSDate() instantiates a new NSDate object, and then timeIntervalSinceDate returns the time difference between that and timeAtPress. That will return a floating point value (technically, a NSTimeInterval).
If you want that as truncated to an Int value, you can just use:
let duration = Int(elapsedTime)