2013-05-15 28 views
9

NSDateFormatter biçimindeki karakterlerden nasıl kurtulur?Kaçış NSDateFormatter Dize

NSDate *currentDate = [NSDate date]; 
NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init]; 
[dateFormater setDateFormat:@"dd/MM/yyyy \\a\\t HH:mm"]; 
NSString *dateFormated = [dateFormater stringFromDate:currentDate]; 

NSLog(@"%@", dateFormated); 
+5

İmi [Tarih formatlayıcılar] (https://developer.apple. [IEEE Tarih Biçimi Belirtimi] (http://www.unicode.org/reports/tr35/ sayfasının yanı sıra dokümanlardaki com/library/ios/# documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html) sayfası tr35-25.html # Date_Format_Pattern s). NSDateFormatter ile çalışan herkes bu sayfaları okumalıdır. – rmaddy

cevap

26

Sen tek tırnak içinde içine alarak metni kaçabilir:

[dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"]; 

docs Gönderen:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm"]; 
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:162000]; 
NSString *formattedDateString = [dateFormatter stringFromDate:date]; 
NSLog(@"formattedDateString: %@", formattedDateString); 
// For US English, the output may be: 
// formattedDateString: 2001-01-02 at 13:00