Tuesday, December 3, 2013

About NSDate turn NSString problems

 
- (IBAction) newTime: (id) sender {
NSData * toDay;
toDay = [[NSData alloc] init];
NSString * stoDay = [ dateFormatter stringFromDate: toDay];
time.text = stoDay;
}

Source above, a circle online search and found say so, but it is wrong (red font office), you ask how this transformation?
If you can, talk about the way also convert other formats of ...
Reply:
Is NSDate, not NSData.
Reply:
LS positive solution.
Reply:
cited a floor reply:
is NSDate, not NSData.

Well, I was wrong word, thank you to correct, but my question is NSData can solve under it? ? ?
Reply:
Amount, sorry, just got it wrong, change over or not right.
Reply:
OK, solved, because Xcode does not know stringFromDate, NSDateFormatter need to instantiate an object, the object is then converted according to ...
 
- (IBAction) newTime: (id) sender {
NSDate * toDay;
toDay = [[NSDate alloc] init];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[DateFormatter setDateFormat: @ "YYYY-MM-DD HH: mm: ss"];
NSString * dateStr = [dateFormatter stringFromDate: [NSDate date]];
[Time setText: dateStr];
}

No comments:

Post a Comment