NSDateFormatter Examples


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.