Posted By

BenClayton on 02/05/11


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

concertman
cnathan


NSDateFormatter Examples


 / Published in: Objective C
 

  1. Using Time and Date Formatting
  2.  
  3. NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
  4. [dateFormat setDateFormat:@"yyyy-MM-dd"];
  5.  
  6. NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
  7. [timeFormat setDateFormat:@"HH:mm:ss"];
  8.  
  9. NSDate *now = [[NSDate alloc] init];
  10.  
  11. NSString *theDate = [dateFormat stringFromDate:now];
  12. NSString *theTime = [timeFormat stringFromDate:now];
  13.  
  14. NSLog(@"\n"
  15.  
  16. "theDate: |%@| \n"
  17. "theTime: |%@| \n"
  18. , theDate, theTime);
  19.  
  20. [dateFormat release];
  21. [timeFormat release];
  22. [now release];

Report this snippet  

You need to login to post a comment.