Created
April 26, 2015 10:28
-
-
Save Tpbradley/3fb7faaa2de23cea940c to your computer and use it in GitHub Desktop.
Date Formatting
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
NSDateComponents *fromComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[_fromDate dateValue]]; | |
NSDateComponents *toComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[_toDate dateValue]]; | |
NSString *fromDateString = [NSString stringWithFormat:@"%li-%li-%li 00:00:00", fromComponents.day, fromComponents.month, (long)fromComponents.year]; | |
NSString *toDateString = [NSString stringWithFormat:@"%li-%li-%li 23:59:59", toComponents.day, toComponents.month, (long)toComponents.year]; | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
// this is imporant - we set our input date format to match our input string | |
// if format doesn't match you'll get nil from your string, so be careful | |
[dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"]; | |
NSDate *dateFromString = [dateFormatter dateFromString:fromDateString]; | |
NSDate *dateToString = [dateFormatter dateFromString:toDateString]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment