Generally written in java+oracle background, may give you back the time style is this:
2014-01-20 13:24:33
Look at this time string is more complex, but the iOS SDK has been packaged for us to convert NSString to any nsdate or nsstring
Using the NSDateFormatter implementation
+ (NSString *) timefromstring: (NSString *) timestring{ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];< C1/>[formatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];//Enter date format nsdate *date = [Formatter datefromstring: timestring];//from NSString get a nsdate nsdateformatter *formatter2 = [[NSDateFormatter alloc] init]; [Formatter2 setdateformat:@ "Yyyy/mm/dd"]; Output Date format nsstring *str = [NSString stringwithformat:@ "%@", [Formatter2 stringfromdate:date]];// Convert from NSDate to nsstring return str;}
in this way, you can convert any received background time string to the type of string you want!
Special attention:
HH rep, 24-hour system
HH stands for 12-hour (if 24-hour time, when converted to HH, a null value is generated)
Original address:
Http://blog.csdn.net/yangbingbinga
iOS development nsdateformatter,nsdate and NSString date conversion, nsstring any format