I have an iOS app which needs to set a few different date labels according to the current day. I am using NSDate
and NSDateFormatter
to do this. However there is something I am not sure about: if the user has an iOS device with their language/localisation set to something other than English, then will my if statements that check to see if it is currently "Monday" or "Tuesday", stop working?
Here is my code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyyMMdd";
NSDate *date = [NSDate date];
dateFormatter.dateFormat = @"EEEE";
NSString *dayString = [[dateFormatter stringFromDate:date] capitalizedString];
NSLog(@"Day: %@", dayString);
if ([dayString isEqualToString:@"Monday"]) {
}
else if ([dayString isEqualToString:@"Tuesday"]) {
}
else if ([dayString isEqualToString:@"Wednesday"]) {
}
else if ([dayString isEqualToString:@"Thursday"]) {
}
else if ([dayString isEqualToString:@"Friday"]) {
}
else if ([dayString isEqualToString:@"Saturday"]) {
}
else if ([dayString isEqualToString:@"Sunday"]) {
}