質問
私は、以下のコード:
[ [NSDate date] descriptionWithLocale: @"yyyy-MM-dd" ]
っていない場合については、dateオブジェクトを返し、以下のフォーマット:"2009-04-23"
ものを返します:木曜日,月23日2009年11:27:03PM GMT+03:00
なぜですか?
よろしくお願いします。
解決
をご利用の方は間違った方法です。代わりにしてみ descriptionWithCalendarFormat:timeZone:locale:
[[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d"
timezone:nil
locale:nil];
またこの方法は異なる形式におい問題です。全文書をできるか こちらの.
編集:ものとしてマイクに留意すべき使用 NSDateFormatter
.あの問題 descriptionWithCalendarFormat:timezone:locale:
によると、アップル記載しています。
他のヒント
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release]; // delete this line if your project uses ARC
NSLog(@"%@",dateString);
また、ほとんどの場合、NSDateFormatter
は、その柔軟性のために好ましいことがあることに注意します。
多くのアプリで日付フォーマッタの再使用から持っていたことに多大なパフォーマンス上の利点もあります。
あなたは利用可能NSDate -descriptionWithCalendarFormat:timeZone:locale:
(私はiPhone /ココアタッチはこれを含んで信じていません)あなたが使用する必要があります<のhref = "http://www.cplusplus.com/reference/clibrary/ctime/を持っていない場合いくつかのCスタイルの文字列とのstrftime /」のrel = "nofollowをnoreferrer">のstrftimeのと周りの猿。あなたはNSDate -timeIntervalSince1970
を使用してNSDateからUNIXタイムスタンプを取得することができます。