Posted By

code4mac on 11/07/12


Tagged

nsstring NSDate


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

mirosso25
cnathan
hawk007


NSString to NSDate


 / Published in: Objective C
 

Convert a NSString to NSDate. You can add time.

  1. //The String dateString is : 2012-01-02. You can define time in the dateFormatter
  2. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3. [dateFormatter setDateFormat:@"YYYY-MM-DD"];
  4. NSDate *dateConvertedFromString = [dateFormatter dateFromString:dateString];
  5. // or directly
  6. //NSDate *dateConvertedFromString = [dateFormatter dateFromString:@"2012-12-21];

Report this snippet  

You need to login to post a comment.