iphone - Which is this NSDateFormatter style Friday, December 18th -
i want know date format friday, december 18th
, standard date format or have hard work this.
thanks.
i don't think th possible achieve via formatters. although can 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];
Comments
Post a Comment