NSDateFormatter,我做错了还是这个bug? [英] NSDateFormatter, am I doing something wrong or is this a bug?

查看:90
本文介绍了NSDateFormatter,我做错了还是这个bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以某种格式打印出日期:

I'm trying to print out the date in a certain format:

NSDate *today = [[NSDate alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *dateStr = [dateFormatter stringFromDate:today];

如果将iPhone设置为24小时,如果用户另一方面用户工作正常已将其设置为24小时时间,然后返回到上午/下午(它可以正常工作,直到您切换此设置)然后它会在最后添加AM / PM,即使我没有要求它:

If the iPhone is set to 24 hour time, this works fine, if on the other hand the user has set it to 24 hour time, then back to AM/PM (it works fine until you toggle this setting) then it appends the AM/PM on the end even though I didn't ask for it:

20080927030337 PM

Am我做错了什么或这是固件2.1的错误?

Am I doing something wrong or is this a bug with firmware 2.1?

编辑1:使描述更清楚

编辑2解决方法:事实证明这是一个错误,修复它我将AM和PM字符设置为:

Edit 2 workaround: It turns out this is a bug, to fix it I set the AM and PM characters to "":

[dateFormatter setAMSymbol:@""];
[dateFormatter setPMSymbol:@""];


推荐答案

使用您在模拟器上发布的代码和2.1固件和24小时时间设置为关闭的手机,当我这样做时,我从来没有将AM / PM附加到dateStr:

Using the code you posted on both the simulator and a phone with the 2.1 firmware and 24-hour time set to off, I never had an AM/PM appended to dateStr when I do:

NSLog(@"%@", dateStr);

您是否正在使用dateStr执行其他任何未在此处发布的内容?你是如何检查价值的?

Are you doing anything else with dateStr that you didn't post here? How are you checking the value?

跟进


尝试打开am / pm设置然后关闭。我也没有问题,直到我这样做。我打印出的方式和你一样。

Try turning the am/pm setting on then off. I didn't have the problem either, until I did that. I am printing it out the same way you are.

好的,我也是这样看的。这必须是一个bug。我建议您提交错误报告,并在此期间检查并过滤掉不需要的字符。

Okay, I see it when I do this also. It's gotta be a bug. I recommend you file a bug report and just check for and filter out the unwanted characters in the meantime.

这篇关于NSDateFormatter,我做错了还是这个bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆