0

I saw this answer : Get current NSDate in timestamp format

But for some reason it gives me errors.

What I need is to be able to specify the timestamp between now and in the next 2 minutes, or interval between last 2 minutes and now.

Eg: interval => now-2minutes to now (Time between previous 2 minutes and now)

Thank you.

Community
  • 1
  • 1
LoveMeow
  • 3,858
  • 9
  • 44
  • 66

2 Answers2

2

If I got it right, this should clarify things for you:

    let calendar = NSCalendar.currentCalendar()

    let now = NSDate()

    let comps = NSDateComponents()
    comps.minute = 2

    let twoMinutesFromNow = calendar.dateByAddingComponents(comps, toDate: now, options: NSCalendarOptions.MatchStrictly)

    let interval = twoMinutesFromNow?.timeIntervalSinceDate(now)

Here is a nice article about handling NSDates with the use of NSCalendar and NSDateComponents

Teo
  • 3,394
  • 11
  • 43
  • 73
1
var curr = NSDate(timeIntervalSince1970: 10000)
var timestep = curr
Memon Irshad
  • 972
  • 1
  • 8
  • 17