0

I converting this string 2016-12-14T03:59:59Z to a NSDate using this way

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];

[formatter dateFromString:rawDate];

When I log this instance it's show 2016-12-14 03:59:59 +0000 but when I try to get the day from the instance using this way

NSDateComponents *components = [[[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian] components:NSCalendarUnitDay fromDate:nsDateInstance];

//Return 13
[components day];

And I don't know why. I've also tried using the CurrentCalendar but got the same result.

Thanks in advance.

BlaShadow
  • 11,075
  • 7
  • 39
  • 60
  • Getting the day could be local time, or daylight Savings time. Long story short, try the same thing but with noon as the time. See here: http://stackoverflow.com/questions/6885896/nsdatecomponents-day-method-returning-wrong-day – Putz1103 Nov 16 '16 at 22:16
  • @Putz1103 No, it's not due to daylight savings. – rmaddy Nov 16 '16 at 22:17
  • @rmaddy, updated my comment, sorry – Putz1103 Nov 16 '16 at 22:17

0 Answers0