Convert NSDate to mm/dd/yyyy

前端 未结 1 985
生来不讨喜
生来不讨喜 2021-01-11 14:24

I know this question is similar to others asked, but I can\'t find where my code is going wrong. I am trying to convert the current date into a mm/dd/yyyy format. Here is wh

相关标签:
1条回答
  • 2021-01-11 15:03

    Check the case:

    mm means minutes

    MM means months

    So your code should probably read

    NSDate *date = [[NSDate alloc]init];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd/yyyy"];
    
    NSLog(@"%@", [formatter stringFromDate:date]);
    
    0 讨论(0)
提交回复
热议问题