我想将这两个变量转换为Swift语言,但我似乎无法找到最好的方法来实现这一点,dateWithTimeIntervalSinceNow
在swift中的工作方式不同。
NSNumber *startDate = @((unsigned long long)([[NSDate dateWithTimeIntervalSinceNow:-(60*60)] timeIntervalSince1970]*10000000));
NSNumber *endDate = @((unsigned long long)([[NSDate date] timeIntervalSince1970]*10000000));
到目前为止我的尝试:
let calendar = NSCalendar.currentCalendar()
let oneDayAgo = calendar.dateByAddingUnit(.CalendarUnitDay, value: -1, toDate: NSDate(), options: nil)
var startNum:NSNumber = oneDayAgo!.timeIntervalSince1970*10000000`
答案 0 :(得分:0)
这大致是你想要做的吗?
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)")