Created
August 7, 2012 07:25
-
-
Save alex-cellcity/3282790 to your computer and use it in GitHub Desktop.
Calculate age from NSDate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Age.h | |
// | |
// Created by Alex Yao on 7/8/12. | |
// Copyright (c) 2012 alex@thecellcity.com. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSDate (Age) | |
- (NSInteger)age; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Age.m | |
// | |
// Created by Alex Yao on 7/8/12. | |
// Copyright (c) 2012 alex@thecellcity.com. All rights reserved. | |
// | |
#import "NSDate+Age.h" | |
@implementation NSDate (Age) | |
- (NSInteger)age | |
{ | |
NSDateComponents *timeOnEarth = [[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:self toDate:[NSDate date] options:0]; | |
return [timeOnEarth year]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment