开发者

how to save and retrieve date+time into sqlite3 database?

开发者 https://www.devze.com 2022-12-09 22:29 出处:网络
i want to save current date+time into database and also want to retrieve it. i know that in objective-C we cannot save date+time directly.

i want to save current date+time into database and also want to retrieve it. i know that in objective-C we cannot save date+time directly. i have double as a field into database and currently I'm saving date by converting it into double.

here is the method for converting date into double-

currentDate=[NSDate date];

startDate=(double)[currentDate timeIntervalSince1970];

now how do i retrieve date back from that double value? or is there another way to save dat开发者_如何学运维es in iPhone SDK.


NSDate *dateFromDouble(double interval) { 
  return [NSDate dateWithTimeIntervalSince1970: interval];
}


Another alternative is to convert the date to ISO 8601 and save it as TEXT; this can be done using -description and -initWithString:. It will make the date slightly larger in the database; but it'll also be a lot more readable for debugging purposes.

0

精彩评论

暂无评论...
验证码 换一张
取 消