In my previous answer I thought you were having issues with SQLite Persistent Objects, but that's not the case. I think you've simply misunderstood what the following code is actually doing:
NSLog(@"The date is %@", [NSDate date]);
The reason why you're getting different log output under different locales is not because of NSDate, it's because of the NSDateFormatter being used under the hood to insert the string representation of [NSDate date]
into your log string using %@
. In fact, NSDate has no concept of "12-hour" or "24-hour" locales -- it's just a representation of a point in time.
Locales come into play when you turn your NSDate into a string, such as in an NSLog statement or as part of an SQL query string. When you want to do that, you should specify your own explicit formatter, like so:
NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:@"yyyy-MM-dd HH:mm:ss" allowNaturalLanguage:NO];
NSLog(@"The date is %s", [formatter stringFromDate:[NSDate date]]);
[formatter release];
Using the above, you should get identical strings regardless of the users' locale settings.
As for your SQL queries, am I right in thinking that you're also using %@
to insert the date into the query string? If so, you should do something like this instead:
NSString* criteriaTemplate = @"WHERE date(due) BETWEEN date(%d) AND date('now', 'localtime')";
NSString* criteria = [NSString stringWithFormat: criteriaTemplate, [myNSDate timeIntervalSince1970]];
NSArray* todayTasks = [Task findByCriteria:criteria];
Hope this helps.