Converting NSString to NSDate (and back again)

后端 未结 17 2676
-上瘾入骨i
-上瘾入骨i 2020-11-21 23:26

How would I convert an NSString like \"01/02/10\" (meaning 1st February 2010) into an NSDate? And how could I turn the NSDat

17条回答
  •  萌比男神i
    2020-11-22 00:11

    Use this method to convert from NSString to NSdate:

    -(NSDate *)getDateFromString:(NSString *)pstrDate
    {
        NSDateFormatter* myFormatter = [[NSDateFormatter alloc] init];
        [myFormatter setDateFormat:@"dd/MM/yyyy"];
        NSDate* myDate = [myFormatter dateFromString:pstrDate];
        return myDate;
    }
    

提交回复
热议问题