Convert date format in returns wrong date xcode [duplicate]

社会主义新天地 提交于 2019-12-02 03:29:31

You need to do below changes:

YYYY --> yyyy

Updated Code:

    NSString *strInputDateString = @"23 May, 2017";
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd MMM, yyyy"];

    //Set new dateFormate
//    23-05-2017
    NSDate *date1 = [dateFormat dateFromString:strInputDateString];
    [dateFormat setDateFormat:@"dd-MM-yyyy"];

    NSString *strOutputDateString = [dateFormat stringFromDate:date1];
    NSLog(@"%@",strInputDateString);
    NSLog(@"%@",strOutputDateString);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!