NSDateFormatter wrong string after formatting

后端 未结 4 1707
独厮守ぢ
独厮守ぢ 2020-12-22 00:55

I receive a date through a string parameter, which is tempDateString, in a [day month year] format (for ex. 01 05 2005):

 NSLog(@\"tempdatestring %@\", tempD         


        
4条回答
  •  渐次进展
    2020-12-22 01:08

    Do this:

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd MM yyyy"];
    NSDate *dayDate = [dateFormatter dateFromString:tempDateString];
    NSLog(@"daydate %@", dayDate);
    NSString *strDate = [dateFormatter stringFromDate:dayDate];
    NSLog(@"strDate :%@",strDate);
    

提交回复
热议问题