I want to determine the day, month and year of the current date in iOS. I found this after searching the net:
NSDate *date = [NSDate date]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [calendar components:(NSDayCalendarUnit) fromDate:date]; NSInteger Day = [components day]; NSInteger month = [components month]; NSInteger year = [components year];
This code shows the day is correct, but the year and month are not displayed as it should be. It shows some numbers, such as 2147483647. I could not find a solution, so please help me fix the code I found, or write a new code that does what I need.
source share