iPhone: How to convert “yyyyMMddThhmmss” format string to NSDate?

前端 未结 3 1498
悲&欢浪女
悲&欢浪女 2021-01-15 21:51

I have a string like \"20121124T103000\" and I want to convert this to NSDate.

I tried converting it with dateFormatter date format \"

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 22:12

    do like this,

    NSString *dateStr = @"20121124T103000";
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyyMMdd'T'hhmmss"];
    NSDate *d = [dateFormat dateFromString:dateStr];
    NSString *st = [dateFormat stringFromDate:d];   
    NSLog(@"%@",st);
    

提交回复
热议问题