简体   繁体   English

iphone NSDate与NSDateFormatter问题

[英]iphone NSDate with NSDateFormatter Problem

All i am trying to do, is to get an NSString with the value of the current date ( NOW ) 我要做的就是获取一个具有当前日期值的NSString(NOW)

with this format: 具有以下格式:

7/14/10 8:20 PM 2010/7/14下午8:20

Exactly like the native mail app of the iPhone. 就像iPhone的本机邮件应用程序一样。

i am using the following code to do it: 我正在使用以下代码来做到这一点:

 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"EEE, dd MMMM yyyy HH:mm:ss ZZ"];
 [dateFormat setDateStyle:NSDateFormatterFullStyle];
 NSString *dateString = [dateFormat stringFromDate:[NSDate date]];

but the still the result is: 但仍然结果是:

Wednesday, July 14, 2010 2010年7月14日,星期三

Does anyone have any idea of how to get this to just WORK ?? 有谁知道如何使它正常工作?

Appreciate your answers.. 感谢您的回答。

setDateStyle:覆盖使用setDateFormat:设置的自定义格式字符串。

Besides that you should call -setDateStyle: first as per Nikolai answer, your formatting string doesn't match your example, which would be produced by eg the following: 除此之外,您应该调用-setDateStyle:首先,按照Nikolai的答案,格式字符串与您的示例不匹配,该示例将由以下示例产生:

[dateFormat setDateFormat:@"M/d/yy h:mm a"];

See the Unicode date format patterns for more details. 有关更多详细信息,请参见Unicode日期格式模式

See Apple's Date Formatting docs. 请参阅Apple的日期格式文档。

I haven't tested it, but try 我没有测试过,但是尝试

 [dateFormat setDateFormat:@"MM/DD/yy"]; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM