gpt4 book ai didi

iphone - 这是 NSDateFormatter 风格,12 月 18 日,星期五

转载 作者:太空狗 更新时间:2023-10-30 03:57:20 27 4
gpt4 key购买 nike

我想知道这个日期格式是什么 Frid​​ay, December 18th 也是这个标准日期格式,或者我必须努力工作才能得到这个。

谢谢。

最佳答案

我认为th 不可能通过格式化程序实现。虽然你可以这样做:

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];

关于iphone - 这是 NSDateFormatter 风格,12 月 18 日,星期五,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5041518/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com