【发布时间】:2015-05-14 05:14:08
【问题描述】:
我有一点问题。 请看这里,理解这个问题。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale systemLocale]];
[dateFormatter setDateFormat:@"dd-MMM-yyyy"];
self.datePicker.userInteractionEnabled=YES;
NSString *dateString=[dateFormatter stringFromDate:datePicker.date];
这是我要返回日期的块。但是当我在那里设置NSLocale 时,这不会给我正确的回应。
我想要dd-MMM-yyyy (24-Mar-2008) 格式的DATE。但它给出了回应:
iOS8.0 及更高版本 --> 24-M03-2004
iOS7.0 及更早版本 --> 24-Month03-2004
由于某些依赖性,我无法从上面的块中删除 [dateFormatter setLocale:[NSLocale systemLocale]];。
请建议我如何处理这个问题,
【问题讨论】:
-
[dateFormat setTimeZone:[NSTimeZone localTimeZone]];而不是 [dateFormatter setLocale:[NSLocale systemLocale]];你会很高兴的
-
你能分享你的 datepicker.date 值吗?
-
@adnan 你的答案是正确的。
-
@muku datepicker.date 值来自 NSDatePicker。
-
这是由于 [dateFormatter setLocale:[NSLocale systemLocale]] 和它唯一受支持的新版本 iOS 所致。希望你能因为这个信息而得到一些逻辑......
标签: ios objective-c iphone nsdate nsdateformatter