xoail
xoail

Reputation: 3064

NSDate after NSDateFormatter is null

Why is the dateformatter returning null? objSelectedNote.notedate is of type NSDate. [NSDate date] works fine...

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd"];
NSLog(@"%@", [df stringFromDate:obj_SelectedNote.notedate]);
NSLog(@"%@", obj_SelectedNote.notedate);
NSLog(@"%@", [df stringFromDate:[NSDate date]]);
[df release];

nslog responses:

2011-06-04 10:31:25.441 ail[40632:207] (null) 
2011-06-04 10:31:27.828 ail[40632:207] 2011-06-04 00:18:23 -0700
2011-06-04 10:31:30.340 ail[40632:207] 2011-06-04

Upvotes: 1

Views: 703

Answers (2)

Bogdan
Bogdan

Reputation: 2617

I have only one user with this problem. And he fixed it switching from 12-h format to 24-h in his Settings. And I still can't reproduce it myself. And I do have proof of this!

Upvotes: 0

xoail
xoail

Reputation: 3064

It turned out there was a problem in retrieving the data from sqlite. This piece code help me solve it.

const char *temp_notedate = (const char *)sqlite3_column_text(selectionStmt, 3);
            if(temp_notedate){
                NSDateFormatter *df = [[NSDateFormatter alloc] init];
                NSString *newstr = [NSString stringWithUTF8String:temp_notedate];
                [df setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
                NSDate * newdate = [df dateFromString:newstr];
                objNotes.notedate =  newdate; 
            }

Upvotes: 1

Related Questions