Friday, May 10, 2013

NSDateFormatter NSDateFormatterBehavior10_0 example ios



NSDateFormatterBehavior - NSDateFormatterBehavior10_0

Constants that specify the behavior NSDateFormatter should exhibit.
typedef enum {
   NSDateFormatterBehaviorDefault = 0,
   NSDateFormatterBehavior10_0    = 1000,
   NSDateFormatterBehavior10_4    = 1040,
} NSDateFormatterBehavior;
Constants
NSDateFormatterBehaviorDefault
Specifies default formatting behavior.
NSDateFormatterBehavior10_0
Specifies formatting behavior equivalent to that in OS X v10.0.
NSDateFormatterBehavior10_4
Specifies formatting behavior equivalent for OS X v10.4.


Example of [NSDateFormatter NSDateFormatterBehavior10_0]

NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterBehavior10_0];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSDate *date = [NSDate date];
NSString * s = [dateFormatter stringFromDate:date];

Example of [NSDateFormatter NSDateFormatterBehavior10_0]
NSDateFormatter * df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[df setTimeZone:[NSTimeZone systemTimeZone]];
[df setFormatterBehavior:NSDateFormatterBehavior10_0];

NSDate *theDate = [df dateFromString:@"2011-04-12 10:00:00"];
NSLog(@"date: %@", theDate);
Example of [NSDateFormatter NSDateFormatterBehavior10_0]
 NSDate *today1 = [[NSDate alloc] init];

NSString *dates = [NSString stringWithFormat:@"%@",[today1 description]];
dates = [dates substringToIndex:10];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterBehavior10_0];
[dateFormat setTimeZone:[NSTimeZone localTimeZone]];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [dateFormat dateFromString:dates];