In iOS 12, I have noticed that the [NSDateFormatter stringFromDate]
method returns an incorrect value on a simulator iPad, but the correct value on a physical iPad.
Example code:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"c"];
NSDate *currentDate = [NSDate date];
// Returns correct value on both physical and simulator iPads (eg. Fri Oct 19 15:39:53 2018)
NSString *currentDateAsString = [dateFormat stringFromDate:currentDate];
// Physical iPad: 5 (correct)
// Simulator iPad: 6 (incorrect)
Both iPads have the same date/time settings (eg. same timezone). What is the cause of this bug?
Check the first weekday on your real and simulator iPads to see if they match:
NSCalendar.current.firstWeekday
and take that value into your calculations on the weekday taken from the date formatter.
The first day of week on iOS depends on the Region settings. Double check the settings in Settings -> General -> Language & Region -> Region on both your real and simulator iPads. Also, it may worth to check the first day of week on your Mac in System Preferences -> Language & Region -> First day of week too.