setDateStyle:
Sets the date style of the receiver.
- (void)setDateStyle:(NSDateFormatterStyle)style
Parameters
- style
- The date style of the receiver. For possible values, see NSDateFormatterStyle.
Example of [NSDateFormatter setDateStyle]
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle :NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateFormat:@"MMMM dd, yyyy kk:mm:ss"];
self.creationDate.text = [dateFormatter stringFromDate:creationTimeStamp];
Example of [NSDateFormatter setDateStyle]
//create a date formatter with standard locale, then:
// have to set a date style before dateFormat will give you a string back
[dateFormatter setDateStyle :NSDateFormatterMediumStyle];
// read out the format string
NSString *format = [dateFormatter dateFormat];
format = [format stringByReplacingOccurrencesOfString:@"y" withString:@""];
[dateFormatter setDateFormat:format];
Example of [NSDateFormatter setDateStyle]
static NSDateFormatter *formatter = nil;
if (!formatter) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle :dateStyle];
[formatter setTimeStyle:timeStyle];
}
NSString *result = [formatter stringFromDate:date];
// reuse
[formatter setDateStyle :anotherDateStyle];
[formatter setTimeStyle:anotherTimeStyle];
NSString *anotherResult = [formatter stringFromDate:anotherDate];