[英]Compare two dates for Countdown Timer Swift2
I'm querying the createdAt column from Parse.我正在从 Parse 查询createdAt列。
My Parse methods are above this code and then I'm doing this:我的 Parse 方法在此代码之上,然后我这样做:
var createdAt = object.createdAt
if createdAt != nil {
let twentyFourHours = NSTimeInterval(60 * 60 * 24)
self.expiresAt = NSDate(timeInterval: twentyFourHours, sinceDate: (createdAt!!))
}
I am querying many dates from Parse.我正在从 Parse 查询许多日期。 However, I'm unable to store them in
createdAt
because createdAt
is of type NSDate?
但是,我无法将它们存储在
createdAt
因为createdAt
是NSDate?
类型NSDate?
. .
I need to make an array, but I can't figure out how to store many NSDate values so that I can compare them.我需要创建一个数组,但我不知道如何存储许多 NSDate 值以便我可以比较它们。
How can I store the values I'm querying and put them into an array so that I can compare many createdAt
dates with the NSTimeInterval
method using this method: NSDate(timeInterval: twentyFourHours, sinceDate: (createdAt!!))
?我怎么能存储我查询值,并把它们放到一个数组,这样我可以比较多
createdAt
与日期NSTimeInterval
使用这种方法方法: NSDate(timeInterval: twentyFourHours, sinceDate: (createdAt!!))
Am I using the correct function?我是否使用了正确的功能?
Thanks in advance.提前致谢。
I guess the easiest way is to store the data as Double我想最简单的方法是将数据存储为 Double
let date = NSDate().timeIntervalSince1970
let doubleDate = Double(date)
Create an array, store and very easy to compare.创建一个数组,存储和比较非常容易。 Than when you query it, just do:
比当您查询它时,只需执行以下操作:
var date = NSDate(timeIntervalSince1970: Double(dateDouble))
exemple:例子:
func exemple() {
// SAVING
// take you date
var array = [Double]()
let dateToSave = NSDate().timeIntervalSince1970
let dateToSave1 = NSDate().timeIntervalSince1970
let dateToSave2 = NSDate().timeIntervalSince1970
let dateToSave3 = NSDate().timeIntervalSince1970
let dateToSave4 = NSDate().timeIntervalSince1970
array.append(Double(dateToSave))
array.append(Double(dateToSave1))
array.append(Double(dateToSave2))
array.append(Double(dateToSave3))
array.append(Double(dateToSave4))
print(array)
let objectToSave = PFObject(className:"SomeDates")
objectToSave["dates"] = array
objectToSave.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
//done
} else {
// done != true :))
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.