NSDateFormatter- stringFromDate不返回AM / PM [英] NSDateFormatter- stringFromDate not returning AM/PM

查看:156
本文介绍了NSDateFormatter- stringFromDate不返回AM / PM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"hh:mm:ss a"];
    NSLog(@"Today's Time: %@", [formatter stringFromDate:[NSDate date]]);

上面的代码只是给出以下输出今天的时间:15:46: 43
我希望输出为今天的时间:3:46 PM
我冲浪了很多,我没有找到一种方式来显示AM / PM。如果有人能帮我找出路,真的有帮助。
我正在使用XCode 6.3,我的设备安装了iOS 8.3。

The above code just gives the following output Today's Time: 15:46:43 I want the output to be Today's Time: 3:46 PM. I surfed a lot and i did not find a way to show AM/PM. Would be really helpful if someone can help me find a way out. I am using XCode 6.3 and my Device has iOS 8.3 installed in it.

推荐答案

检查您的设备设置24小时。如果是,则将其关闭。

您的代码完全正常。我得到的输出如下所示:
今天的时间:04:31:58 PM

Your code is perfectly fine. I am getting output as shown below : Today's Time: 04:31:58 PM

如果你不想显示秒使用这段代码: / p>

If you don't want to show seconds use this code :

[formatter setDateFormat:@"hh:mm a"];

这篇关于NSDateFormatter- stringFromDate不返回AM / PM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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