Only time using NSDate in iphone


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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];

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.