NSDate comparison in custom format Issue
I want compare two dates. I am getting device date in yyyy-dd-mm format and getting mm-dd-yyyy from webservices. I want to change device date format and get that changed date in NSDate
object. Here is my code:
NSDate *today = [[NSDate alloc] init];
NSLog(@"today : %@", today);
NSDateFormatter *dateFormatter = [[N开发者_如何学JAVASDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM dd yy"];
NSString *tString = [dateFormatter stringFromDate:today];
NSLog(@"tString : %@",tString);
NSDate *date = [dateFormatter dateFromString:tString];
NSLog(@"date : %@",date);
You are saying date coming from webservice is in mm-dd-yyyy format..Then convert it into NSDate like this
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSDate *convertedDate = [dateFormatter dateFromString:yourDateStringFromWeb];
You have device date already with you..Now you can compare two NSDate objects in many ways..See this and this..
精彩评论