0

When I try to parse a date value into my core data using JSON, the date value is deducted by one day. e.g in JSON I write: "date": "14/03/13" and it stores it as 13/03/13 in my coredata. Any ideas as to why this is happening?? Below is my code

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd - MM - yy"];
    [dateFormatter setCalendar:[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]];

    dayinfo.date = [dateFormatter dateFromString:[obj objectForKey:@"date"]];
4

1 に答える 1

3

日付のローカル タイムゾーンに従って TimeZone を設定してみてください。

[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

また

[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];

また

[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
于 2013-03-27T15:37:04.470 に答える