Converting Variable from Obj-C To Swift

603 views Asked by At

I want to convert these two variables into Swift language but I cant seem to figure out the best way to do this bc of the fact that dateWithTimeIntervalSinceNow works differently in swift.

NSNumber *startDate = @((unsigned long long)([[NSDate dateWithTimeIntervalSinceNow:-(60*60)] timeIntervalSince1970]*10000000));
NSNumber *endDate = @((unsigned long long)([[NSDate date] timeIntervalSince1970]*10000000));

My attempt so far:

let calendar = NSCalendar.currentCalendar()
let oneDayAgo = calendar.dateByAddingUnit(.CalendarUnitDay, value: -1, toDate: NSDate(), options: nil)
var startNum:NSNumber = oneDayAgo!.timeIntervalSince1970*10000000`
1

There are 1 answers

0
russellm On

Is this roughly what you're trying to do?

let startInterval = NSDate(timeIntervalSinceNow: -(60*60)).timeIntervalSince1970
let endInterval = NSDate().timeIntervalSince1970

print("start: \(startInterval) end: \(endInterval)")

let actualStart = NSDate(timeIntervalSince1970: startInterval)
let actualEnd = NSDate(timeIntervalSince1970: endInterval)

print("one hour ago: \(actualStart) now: \(actualEnd)")