Is Friday with date format "c" returned as 5 or 6?

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?


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

链接地址: http://www.djcxy.com/p/35178.html

上一篇: 文件属性是否包含毫秒? 目的

下一篇: 星期五是日期格式“c”是5还是6?