我想显示如下数字
How should I find the correct ordinal suffix (st, nd, rd or th) for each number in my code?
有没有办法使用NSNumberFormatter获得'th''st''nd''rd'数字结尾?
编辑:
看起来它不存在.这就是我正在使用的.
+(NSString*)ordinalNumberFormat:(NSInteger)num{
NSString *ending;
int ones = num % 10;
int tens = floor(num / 10);
tens = tens % 10;
if(tens == 1){
ending = @"th";
}else {
switch (ones) {
case 1:
ending = @"st";
break;
case 2:
ending = @"nd";
break;
case 3:
ending = @"rd";
break;
default:
ending = @"th";
break;
}
}
return [NSString stringWithFormat:@"%d%@", num, ending];
}
Run Code Online (Sandbox Code Playgroud)
改编自nickf的答案这里 是否有一种简单的方法可以获得数字的"st","nd","rd"和"th"结尾?
我想将DateTime变量转换为以下格式:"2014年7月26日星期四".
什么是正确的方法.
谢谢