Posted By

espinallab on 02/23/10


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

zingo
umang_nine
cnathan


NSDateFormatter


 / Published in: Objective C
 

URL: http://forums.macrumors.com/showthread.php?t=475188

Good to know this

  1. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  2.  
  3. [dateFormatter setDateFormat:@"yyyy"];
  4. int year = [[dateFormatter stringFromDate:[NSDate date]] intValue];
  5.  
  6. [dateFormatter setDateFormat:@"MM"];
  7. int month = [[dateFormatter stringFromDate:[NSDate date]] intValue];
  8.  
  9. [dateFormatter setDateFormat:@"dd"];
  10. int day = [[dateFormatter stringFromDate:[NSDate date]] intValue];
  11.  
  12. [dateFormatter setDateFormat:@"HH"];
  13. int hour = [[dateFormatter stringFromDate:[NSDate date]] intValue];
  14.  
  15. [dateFormatter setDateFormat:@"mm"];
  16. int minute = [[dateFormatter stringFromDate:[NSDate date]] intValue];
  17.  
  18. [dateFormatter setDateFormat:@"ss"];
  19. int second = [[dateFormatter stringFromDate:[NSDate date]] intValue];
  20.  
  21. [dateFormatter release];

Report this snippet  

You need to login to post a comment.