iOS: How to get a proper Month name from a number?

前端 未结 11 872
一向
一向 2020-11-30 22:43

I know that the NSDateformatter suite of functionality is a boon for mankind, but at the same time it is very confusing to me. I hope you can help me out.

Somewhere

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 23:21

    NSDate to NSString -> As Dateformat Ex: 2015/06/24

            NSDateFormatter *dateformate=[[NSDateFormatter alloc]init];
            [dateformate setDateFormat: @"yyyy/MM/dd"];
            NSString *date = [dateformate stringFromDate:selectedDate]; // Convert date to string
    

    NSDate to NSString -> As Dateformat Ex: 2015 June 24, 1:02 PM

            [dateformate setDateFormat:@"yyyy MMMM dd, h:mm a"];
            NSString *displayDate = [dateformate stringFromDate:selectedDate]; // Convert date to string
            NSLog(@"date :%@",date);
            NSLog(@"Display time = %@", displayDate);
    

提交回复
热议问题