如何获得约会和约会时间采用 (MM/dd/yyyy hh:MM a) 格式?
在我的应用程序中,我必须显示日期和日期时间就这样,
2011年10月19日下午3点
目前我编写此代码,
NSDateFormatter *formatar=[[NSDateFormatter alloc] init];
[formatar setDateFormat:@"MM/dd/YYYY HH:mm a"];
[formatar setTimeStyle:NSDateFormatterShortStyle];
NSString *st=[formatar stringFromDate:[NSDate date]];
但以这种格式获取日期:
2011年10月19日15点
那么,我怎样才能以这种 10/19/2011 3pm 格式获得它?
In my app I have to show Date & Time Like this,
10/19/2011 3pm
Currently I write this code,
NSDateFormatter *formatar=[[NSDateFormatter alloc] init];
[formatar setDateFormat:@"MM/dd/YYYY HH:mm a"];
[formatar setTimeStyle:NSDateFormatterShortStyle];
NSString *st=[formatar stringFromDate:[NSDate date]];
But Getting date in this format:
10/19/2011 15.00
So, How can i get that in this 10/19/2011 3pm Format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要对日期格式进行一些细微的更改,以使其按照您的需要工作。
1.您的日期格式应仅包含小时(个位数),不包含分钟。
2.小时应采用12小时格式,即“h”而不是“H”,以便“a” 去工作。最后,删除“h”和“a”之间的空格。
You need to do some minor changes to the date format to make it work as you need.
1.Your date format should contain only the hour(single-digit) and no minutes.
2.The hour should be in 12 hour format ie., "h" not "H" in order for "a" to work. Finally, remove the space between "h" and "a".