本文介绍了转义 NSDateFormatter 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 NSDateFormatter 格式转义字符?
How to escape characters from NSDateFormatter format?
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); 推荐答案您可以将文本括在单引号中:
You can escape text by enclosing it in single quotes:
[dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"];来自 文档:
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更多推荐
转义 NSDateFormatter 字符串
发布评论