Created
March 14, 2012 03:31
-
-
Save cdesch/2033820 to your computer and use it in GitHub Desktop.
Simple NSDate Components - Easy to break into pieces
This file contains hidden or 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 *currDate = [NSDate date]; //Current Date | |
NSDateFormatter *df = [[NSDateFormatter alloc] init]; | |
//Day | |
[df setDateFormat:@"dd"]; | |
NSString* myDayString = [NSString stringWithFormat:@"%@", [df stringFromDate:currDate]]; | |
//Month | |
[df setDateFormat:@"MM"]; //MM will give you numeric "03", MMM will give you "Mar" | |
NSString* myMonthString = [NSString stringWithFormat:@"%@", [df stringFromDate:currDate]]; | |
//Year | |
[df setDateFormat:@"yy"]; | |
NSString* myYearString = [NSString stringWithFormat:@"%@", [df stringFromDate:currDate]]; | |
//Hour | |
[df setDateFormat:@"hh"]; | |
NSString* myHourString = [NSString stringWithFormat:@"%@", [df stringFromDate:currDate]]; | |
//Minute | |
[df setDateFormat:@"mm"]; | |
NSString* myMinuteString = [NSString stringWithFormat:@"%@",[df stringFromDate:currDate]]; | |
//Second | |
[df setDateFormat:@"ss"]; | |
NSString* mySecondString = [NSString stringWithFormat:@"%@", [df stringFromDate:currDate]]; | |
//NSLog(@"Year: %@, Month: %@, Day: %@, Hour: %@, Minute: %@, Second: %@", myYearString, myMonthString, myDayString, myHourString, myMinuteString, mySecondString); | |
//[df release]; //if not ARC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment