Friday, May 10, 2013

NSDateFormatter setDefaultFormatterBehavior example ios


setDefaultFormatterBehavior:

Sets the default formatting behavior for instances of the class.
+ (void)setDefaultFormatterBehavior:(NSDateFormatterBehavior)behavior
Parameters of [NSDateFormatter setDefaultFormatterBehavior]
behavior
The default formatting behavior for instances of the class. For possible values, seeNSDateFormatterBehavior.

Example of [NSDateFormatter setDefaultFormatterBehavior]
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *date = [formatter dateFromString:@"2013-03-29T15:27:00Z"];
Example of [NSDateFormatter setDefaultFormatterBehavior]
[NSDateFormatter setDefaultFormatterBehavior :NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
[dateFormatter setLocale:usLocale];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];

Example of [NSDateFormatter setDefaultFormatterBehavior]
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];

NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:<NSString containing date>];