how to convert string into date format in iOS?

后端 未结 2 677
天涯浪人
天涯浪人 2021-01-26 06:09

I have string from web service like 12/31/2013 09:12:15 A.M. Now I Want convert it like 12 Dec 2013 09:12:15 A.M. with the use of NSDAteFormatter

2条回答
  •  旧巷少年郎
    2021-01-26 06:39

    I'm giving you the answer, but downvoting your question for being too elementary and whose solution could easily found with a simple search.

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"];
    NSDate *date = [formatter dateFromString:myDateString];
    [formatter setDateFormat:@"dd MMMM yyyy aa:mm:ss a"];
    NSString *newDate = [formatter stringFromDate:date];
    

提交回复
热议问题