NSDateFormatter wrong date on the simulator, correct date on the device

I create a calendar and find out the first day of the month I make

[formatter setDateFormat:@"e"];
int startDay = [[formatter stringFromDate:newDate] intValue];

On the device, this works correctly, and the 1st day of the month is in the correct day. But on the simulator it is the next day. Although this is not very important for the simulator, it kind of drives me crazy, thinking that I did something wrong. I tried to set the language standard for formatting, but no difference, and I don't think so. Can anyone shed some light on this?

Is there a better way to create a calendar on a side note than this?

Update: It seems that if I do not set the locale, it works fine on the device, but on the simulator it is not. If I set the locale to en_US, none of them will work. I'm in Aust, if that changes anything, but I'm sure that the United States and Aust have the same calendar: /

+3
source share
3 answers

This does not seem to be a solution. Changing the time zone on the device does not cause a problem, and all log output matches the correct time zone, but NSDate seems to pull the time zone from two different places on the simulator, possibly one for Cupertino and one for the local one.

, , (, ), , , , . .

0

, . NSDate . .

, [[NSCalendar currentCalendar] firstWeekDay].

0

, ? WeekDay, - . , ...

0

Source: https://habr.com/ru/post/1737280/


All Articles