I am having following objective -C code. dateServer , dateClient are showing same value, but actually they should be different, because of which timeDiff is coming null.
NSDate *dateClient = [NSDate date];
[NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"PDT"]];
NSDate *dateServer = [NSDate date];
NSLog(@"dateServer=%@",[dateServer description]);
NSLog(@"dateClient=%@",[dateClient description]);
NSTimeInterval timeDiff = [dateClient timeIntervalSinceDate:dateServer];
NSString *dateStr = @"2012-09-21 05:34:24";
// Convert string to date object
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *dateNew = [formatter2 dateFromString:dateStr];
NSLog(@"date new %@" , [dateNew description]);
At the end, date new is coming something other than the string specified. Why is this happening, i just want to convert string to date.
Can anybody suggest what could be wrong in both the places.
Thanks in advance.
Use the below code