Posted By

saravanadel on 07/16/10


Tagged

iphone NSDate


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

alfredbaudisch
umang_nine
bobbym245
rvachere
sb
idevmartin
Tintenklecks
cnathan


Only time using NSDate in iphone


 / Published in: Objective C
 

URL: http://www.satosoft.com/index.php/2009/02/05/using-nsdate-for-the-time-andor-date/

  1. // Get the time
  2. NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  3. NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
  4. NSDate *date = [NSDate date];
  5. NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
  6.  
  7. // Turn the date into Integers
  8. NSInteger year = [dateComponents year];
  9. NSInteger month = [dateComponents month];
  10. NSInteger day = [dateComponents day];
  11. NSInteger hour = [dateComponents hour];
  12. NSInteger min = [dateComponents minute];
  13. NSInteger sec = [dateComponents second];

Report this snippet  

You need to login to post a comment.