iphone - NSTimeInterval of today with time zero (midnight) -
how can calculate nstimeinterval of today hour minute , seconds zero?
i know nstimeinterval of today it's this:
nstimeinterval today = [[nsdate date] timeintervalsince1970];
but how can reset time?
nsdate *currentdate = [nsdate date]; nsdatecomponents *currentdatecomponents = [calendar components:nshourcalendarunit | nsminutecalendarunit | nssecondcalendarunit fromdate:currentdate]; nsdatecomponents *currentdatetomidnight = [[nsdatecomponents alloc] init]; [currentdatetomidnight sethour:-[currentdatecomponents hour]]; [currentdatetomidnight setminute:-[currentdatecomponents minute]]; [currentdatetomidnight setsecond:-[currentdatecomponents second]]; nsdate *midnight = [calendar datebyaddingcomponents:currentdatetomidnight todate:currentdate options:0]; nstimeinterval todaytimeinterval = [midnight timeintervalsince1970];
Comments
Post a Comment