0

私はiPhoneアプリの作成に取り組んでいます。現在の日付を次の形式で取得したい。

Tur, 18 Apr 2013 09:20:47

次のコードで試しました。

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[dateFormatter setDateFormat:@"E, dd MMM yyyy HH:mm:ss"];
NSString *formattedDate = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];

問題は、iPhone の地域が米国ではないため、次の文字列が表示されることです。

木, 18 4月 2013 09:20:47

どうすればこれを解決できますか?

4

2 に答える 2

2

locale日付のプロパティを設定して米国形式で取得する

dateFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]
                                                                  autorelease];

また

 [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
于 2013-04-18T09:32:12.493 に答える
0

私は長い間NSDateFormatterを使用していませんが、いくつかのリンクを証明しています-

理解を深めるために参照できます-

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.htmlおよび

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

お役に立てば幸いです。

于 2013-04-18T10:31:25.900 に答える