NSLog показывает предыдущую дату
Я хочу получить все записи из основных данных, добавленных между двумя датами. Я используюNSPredicate
, Поскольку я не получаю правильный результат, я попытался записать дату. Она показывает предыдущие даты. После поиска в Google некоторое время я добавил
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
к моему коду. Теперь он показывает правильные даты, но результаты по-прежнему неверны.
Это код, который я использовал.
NSDate *fromDate = [[self dateFormatter]dateFromString:self.fromDateField.text];
NSLog(@"%@",fromDate);
NSDate *toDate = [[self dateFormatter]dateFromString:self.toDateField.text];
NSLog(@"%@",toDate);
NSComparisonResult result = [fromDate compare:toDate];
switch (result) {
case NSOrderedAscending:
{
//code
}
- (NSDateFormatter *)dateFormatter
{
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil)
{
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
}
return dateFormatter;
}
заранее спасибо