开发者

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜