助けが必要です.この日付は、この形式のUIlabelに 04/26/2013 あります。04.26.2013 に再フォーマットするにはどうすればよいですか? 私はすでに以下のコードを持っています:
UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(xx, xx, xx, xx)];
[timelabel setText:dateToday];
dateToday
値は04/26/2013
。
助けが必要です.この日付は、この形式のUIlabelに 04/26/2013 あります。04.26.2013 に再フォーマットするにはどうすればよいですか? 私はすでに以下のコードを持っています:
UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(xx, xx, xx, xx)];
[timelabel setText:dateToday];
dateToday
値は04/26/2013
。
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM.dd.yyyy"];
NSString *stringFromDate = [formatter stringFromDate:[NSDate date]];
NSLog(@"today : %@", stringFromDate);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM.dd.yyyy"];
NSDate *date = [dateFormatter dateFromString:dateToday];
if(date != nil) {
NSString *formattedDateString = [dateFormatter stringFromDate:date];
[timelabel setText:formattedDateString];
} else {
[timelabel setText:@"Invalid Date"];
}
エラーチェックを追加しました。入力文字列が有効な日付文字列かどうかを常に確認してください。
timelabel.text = [dateToday stringByReplacingOccurrencesOfString:@"/" withString:@"."];