I want to know which is this date format Friday, December 18th
and also is this standard date format or i have to some hard work to get this.
Thanks.
I don't think the th is possible to achieve via formatters. Although you can do it like this:
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEEE, MMMM d"];
NSString *dateString = [dateFormat stringFromDate:today];
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *dtComp = [cal components:unitFlags fromDate:today];
switch ([dtComp day]) {
case 1:
case 31:
case 21:
dateString = [dateString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%i",[dtComp day]] withString:[NSString stringWithFormat:@"%ist",[dtComp day]]];
break;
case 2:
case 22:
dateString = [dateString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%i",[dtComp day]] withString:[NSString stringWithFormat:@"%ind",[dtComp day]]];
break;
case 3:
case 23:
dateString = [dateString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%i",[dtComp day]] withString:[NSString stringWithFormat:@"%ird",[dtComp day]]];
break;
default:
dateString = [dateString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%i",[dtComp day]] withString:[NSString stringWithFormat:@"%ith",[dtComp day]]];
break;
}
[dateFormat release];
@Robin Help with NSDateFormatter is something which will help u a lot in this case of NSDateFormatter
, you really have to work hard to get this format,Just see the link i had shared with you.
Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With