ios - How to reuse a NSString method? -
I am writing a method that takes the string and gives the string I'm trying to use it in some other method I am
- (NSString *) formatDate: (NSString *) showStartDateTime {NSTimeZone * tz = [NSTimeZone Time ZoneWithName: @ "UTC"]; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [Date-time set-timezone: TJ]; [DateFormatter setDateFormat: @ "EEE MM / DD / Yay"]; NSDate * dattt = [dateFormatter dateFromString: showStartDateTime]; [DateFormatter setDateFormat: @ "yyyy-MM-dd"]; NSString * tempo2 = [dateFormatter stringFromDate: dattt]; Return tempo 2; } In this way I am using it. [Self format date: @ "Venus 08/08/2014"] Is this the right way to use it?
NSString * hellostring = [Self format date: @ "Venus 08/08/2014"]; NSLog (@ "% @", hellostring); I know that this does not work. Any suggestion is appreciated.
I wrote a command line app and it was not already able to run dateFromString : As a result of Neil, I added dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier: @ "en_US_POSIX"] - (NSString *) FormatDate: (NSString *) showStartDateTime {NSTimeZone * tz = [NSTimeZone timezonename: @ "UTC"] ;; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [Date-time set-timezone: TJ]; DateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier: @ "en_US_POSIX"]; [DateFormatter setDateFormat: @ "EEE MM / DD / Yay"]; NSDate * dattt = [dateFormatter dateFromString: showStartDateTime]; [DateFormatter setDateFormat: @ "yyyy-MM-dd"]; NSString * tempo2 = [dateFormatter stringFromDate: dattt]; Return tempo 2; } now returns 2014-08-08
Comments
Post a Comment