Friday, May 10, 2013

NSDateFormatter dateStyle example ios


Returns the date style of the receiver.
- (NSDateFormatterStyle)dateStyle
Return Value of [NSDateFormatter dateStyle]
The date style of the receiver. For possible values, see NSDateFormatterStyle.
Example of [NSDateFormatter dateStyle]
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 dateStyle]
//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 dateStyle]
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];