iphone sqlite NSDate错误
我在iphone应用程序中使用核心数据,但在某些情况下,我使用sqlite访问数据,并且NSDate出现问题.
i use core data in my iphone app, but in some case i use sqlite to access to data and ia have a problem with NSDate.
NSDate *now = [NSDate date];
NSCalendar *calender = [NSCalendar currentCalendar];;
NSDateComponents *comp = [calender components:NSYearCalendarUnit fromDate:now];
[comp setDay:1];
[comp setMonth:1];
NSDate *yearAgo = [calender dateFromComponents:comp];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date > %@",yearAgo];
此代码有效并从年初开始选择记录,但是如果我使用sqlite原始查询
This code works and select records from the start of year, but if i use sqlite raw query
NSDate *current=[NSDate date];
NSDateComponents *comps = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit |NSYearCalendarUnit) fromDate:current];
[comps setDay:1];
[comps setMonth:1];
NSDate *yearDate = [gregorian dateFromComponents:comps];
[where appendFormat:@"zdate > '%@' ",yearDate];
我有一个问题,错误的日期由记录决定,在核心日期中具有日期的记录(如2008年1月1日)在sqlite中具有的日期类似于1977年.如何解决?可能是我在查询中使用NSDate错了吗?
I have a problem, wrong date determined by the records, Records that in core date has date like 2008-01-01 in sqlite have dates like 1977 year. How to fix it? May be I was wrong to use NSDate in the query?
在某些情况下,您需要在SQLite数据库中的日期上加上31年.
In some cases you'll need to add 31 years to the dates in the SQLite DB.
摘自该书: iPhone取证:恢复证据,个人数据和公司资产乔纳森·兹齐亚斯基(Jonathan Zdziarski)在日历事件中:
From the book: IPhone Forensics: Recovering Evidence, Personal Data, and Corporate Assets By Jonathan Zdziarski On calendar events:
与大多数时间戳不同iPhone,这是标准的Unix时间戳记,这里使用的时间戳记是RFC 822时间戳,代表日期偏移量到1977.要转换在此日期之前,确定实际的RFC822加上31年的时间戳.
Unlike most timestamps used on the iPhone, which are standard Unix time-stamps, the timestamp used here is an RFC 822 timestamp representing the date offset to 1977. To convert this date, determine the actual RFC 822 time-stamp and add 31 years.