tags:

views:

26

answers:

1

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  A: 

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"];.

DarkDust
Nice touch, but maybe I haven't put my question directly. The result of the solution should be a constant according which I can say "OK today is Friday" or whatever day. When I use "cccc" I definitely get a string which says the name of day in week but in different locale I get different string and cannot use it to determinate what day of week is today. I want to use this value to count some Timer action.
Vanya
OK, I tried the solution with firstWeekday and works for me...in US settings getting 1 in European getting 2..hope there no other. :o) Thank you
Vanya