-2

I'm using NSDateFormatter like following:

- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d {
NSLog(@"calendarMonthView didSelectDate %@",d);
NSDate *tempDate = [[NSDate alloc]init];// = d;
NSString *selectedDate = @"2013-02-01 00:00:00 +0000";
//NSString *selectedDate = @"2013-02-04";
NSDateFormatter *dateformatter = [[NSDateFormatter alloc]init];
[dateformatter setDateFormat:@"yyyy-MM-DD hh:mm:ss ZZZZ"];
tempDate = [dateformatter dateFromString:selectedDate];
//if([tempDate compare:d])
if([tempDate isEqualToDate:d])
{
  flagtoCheckSelectedCalendarDate = 1;
}
if(flagtoCheckSelectedCalendarDate == 1)
{
    [self viewDidLoad];
}
if(flagtoCheckSelectedCalendarDate == 2)
{
    [self viewDidLoad];
}
//[table reloadData];

}

Why is this output me wrong date?Where I'm going wrong??Please suggest.

bapi
  • 1,903
  • 10
  • 34
  • 59
  • please show the output you are getting and tell us what behaviour you expected to see instead – Damo Feb 01 '13 at 13:16
  • Does you know the datformatter of NSString *selectedDate used previously. Need to use same other wise it will redirect null. – Madhu Feb 01 '13 at 13:19
  • http://stackoverflow.com/questions/14644329/nsstring-compair-is-throwing-exception-sigabt/14644440#comment20461920_14644440 – Stavash Feb 01 '13 at 13:23
  • 3
    I know this is not related to your question. However, it is not adivsable calling viewDidLoad on your own. You should leave that to the API. If things happen in viewDidLoad which you like to call again later on your own, then move that to a third method (like configureView) and call configureView instead. You can of course call configureView from your viewDidLoad too, to avoid and duplication of code. – Hermann Klecker Feb 01 '13 at 13:28

1 Answers1

0

[dateformatter setDateFormat:@"yyyy-MM-DD hh:mm:ss ZZZZ"];


The DD in your formatter string is wrong. Capital D is day number within the year. You want d.

d:1~31 (0 padded Day of Month)

D:1~366 (0 padded Day of Year)

Community
  • 1
  • 1
John
  • 2,640
  • 1
  • 16
  • 16