Converting NSString to NSDate (and back again)

后端 未结 17 2478
-上瘾入骨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:16

    NSString *dateStr = @"Tue, 25 May 2010 12:53:58 +0000";
    
    // Convert string to date object
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"];
    NSDate *date = [dateFormat dateFromString:dateStr]; 
    [dateFormat release];
    

提交回复
热议问题