ios - Weird date result adding 1 month to a given date -


I am using the following code to get the date of the next week from the date of 12:00: / P>

  NSDT * now = [date of NSDT]; NSCalendar * Calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSDateComponents * Component = [Calendar component: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnitDate from: now]; [Component sethour: 0]; NSDT * nowadays = [calendar date edit] components;] IntDatOd = 7; NSDT * tomorrow date = [date of day date to date: 60 * 60 * 24 * dinoAud]; NSString * stringDate = [NSString stringWithFormat: @ "% @", yesterday's date]; TodoItemDueDateText.text = stringDate; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [DateFormatter setDateFormat: @ "EEEE, DD MMMM YYYY"]; NSString * fechasimulada = [dateFormatter stringFromDate: tomorrowDate]; DateFieldSimulatedText.text = Copy the Fade;  

If I log the date of the result, then it is working fine.

Now, the date of the next month from the date of the same number 12:00 dated:

  NSDT * now = [date of NSDT]; NSCalendar * Calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSDateComponents * Component = [Calendar component: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnitDate from: now]; [Component sethour: 0]; NSDT * nowadays = [calendar date edit] components;] // NSDT * today = [NSDT date]; NSDateComponents * dateComponents = [[NSDateComponents alloc] init]; [DateComponents setMonth: 1]; // NSCalendar * Calendar = [NSCalendar Current Calendar]; NSDT * CalDown = [calendar dated dateaddingCompanyant: datecontent to date: todaydate option: 0]; NSString * stringDate = [NSString stringWithFormat: @ "% @", yesterday's date]; TodoItemDueDateText.text = stringDate; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [DateFormatter setDateFormat: @ "EEEE, DD MMMM YYYY"]; NSString * fechasimulada = [dateFormatter stringFromDate: tomorrowDate];  

I do not know why, but the second piece of code gives the expected date, but -1 hour.

Update:

I will show you dates:

Source date (12 o'clock in the morning) +7 hours

Enter image details here

The date of the next week from the last date:

Enter the image details here

The date of the next month from the previous date: / P>

Enter image details here

NSDate account to save daylight Ng takes If you cross a DST day, you will experience this problem.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -