objective-c – Escape NSDateFormatter String

前端之家收集整理的这篇文章主要介绍了objective-c – Escape NSDateFormatter String前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何从NSDateFormatter格式转义字符?
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);

解决方法

您可以通过将其包含在单引号中来转义文本:
[dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"];

docs

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
原文链接:https://www.f2er.com/c/115049.html

猜你在找的C&C++相关文章