I have a class which converts multiple date formats.
It works when I do this:
-(NSString*)getTimeStampWithFormat:(NSString*) formatStr{
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:formatStr];
NSString *currentDate = [dateFormatter stringFromDate:[NSDate date]];
return currentDate;
}
it does not work when I do this
-(void) initDF{
dateFormatter = [[NSDateFormatter alloc] init];
}
-(NSString*)getTimeStampWithFormat:(NSString*) formatStr{
[dateFormatter setDateFormat:formatStr];
NSString *date = [dateFormatter stringFromDate:[NSDate date]];
return currentDate;
}
I am calling the getTimeStampWithFormat: method multiple times to convert different formats. In the second approach, I am allocating memory only once and converting multiple times it gives nil.
Any help would be appreciated, thanks.
As apple said:
But I am wondering why it always return nil, could you please show us some of the format strings?
Note: Any body know how to add comment to the question? I cannot find the ‘comment’ button.