1
votes

Initially I thought that using this code

+ (NSString *)getDayOfTheWeek:(NSDate *)date format:(NSString*)format
{
 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
 dateFormatter.dateFormat = format;
 NSString *formattedDateString = [dateFormatter stringFromDate:date];
 NSLog(@"Des pico je: %@",formattedDateString);
 return formattedDateString;
}
NSDate *now = [NSDate date];
NSString *today = [self getDayOfTheWeek:now format:@"c"]

should return a string with a number for each day, but it gets different results for different regional format settings. (Mon = 1 or Sun = 1) and maybe some variations. don't know. So is there a common way to get this solution generically for all region date type settings on iPhone easily?

1

1 Answers

2
votes

The "c" is the stand-alone local day of week. Stand-alone means it's meant to be used without any further date context (as opposed to "e"). And the local day of week is dependent on the locale, i.e. which day does the locale dictate as being the first day of the week. So Friday can be either 5 or 6, depending on the locale.

To find out which day is the first day of the week you can use [[NSCalendar currentCalendar] firstWeekday].

But if you want just a string with the name of today's day, as in "Monday", "Tuesday", etc. you can use NSString *today = [self getDayOfTheWeek:now format:@"cccc"];.