Personal feeling, more concise than the way of nsdatecomponents. The simple test is under, no problem. If you have any questions to test, please give us feedback.
TimeIntervalSince1970 is based on GMT time and needs to be corrected in time zone.
nstimezone* zone = [Nstimezone systemtimezone];
Nstimeinterval interval = olddate.timeintervalsince1970;
Nstimeinterval newinterval = Interval-fmod (interval+zone.secondsfromgmt,60*60*24);
The remainder of the interval minus interval divided by the number of seconds in a day.
Nstimeinterval is actually a double type, and% can only be used with the int type, so you need to use the FMOD function.
nsdate* newdate = [NSDate datewithtimeintervalsince1970:newinterval];
In a nsdatecomponents way:
unsigned int flags = Nsyearcalendarunit | Nsmonthcalendarunit | Nsdaycalendarunit;
nscalendar* calendar = [Nscalendar Currentcalendar];
nsdatecomponents* components = [Calendar components:flags fromdate:date];
nsdate* dateonly = [Calendar datefromcomponents:components];