ios - Comparing uipickerdate to current date -
here code have 2 datepickers need compare them current date if condition or switch.
nsdateformatter *dateformatter = [[nsdateformatter alloc]init]; dateformatter.timezone=[nstimezone defaulttimezone]; dateformatter.timestyle=nsdateformattershortstyle; dateformatter.datestyle=nsdateformattershortstyle; nsstring *datetimestring=[dateformatter stringfromdate:starttime.date]; nslog(@"start time %@",datetimestring); nsdateformatter *dateformatter2 = [[nsdateformatter alloc]init]; dateformatter2.timezone=[nstimezone defaulttimezone]; dateformatter2.timestyle=nsdateformattershortstyle; dateformatter2.datestyle=nsdateformattershortstyle; nsstring *datetimestring2=[dateformatter2 stringfromdate:endtime.date]; nslog(@"end time %@",datetimestring2); in .h
@property (weak, nonatomic) iboutlet uidatepicker *starttime; @property (weak, nonatomic) iboutlet uidatepicker *endtime; how do that? need store them nsdate or nstime since need time?
also, there if range in objective c?
thanks,
just add this:
if ([[nsdate date] isequaltodate:starttime.date]) { nslog(@"currentdate equal starttime"); } if ([[nsdate date] isequaltodate:endtime.date]) { nslog(@"currentdate equal endtime"); } if want calculate interval between 2 dates use method
- (nstimeinterval)timeintervalsincedate:(nsdate *)anotherdate if([starttime.date timeintervalsincedate:[nsdate date]] > 0) { //start time greater today } else if([starttime.date timeintervalsincedate:[nsdate date]] < 0) { //start time less today } else { //both dates equal } for knowing when application has entered background use notifications add statement in viewdidload
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(applicationenteredbackground) name:uiapplicationdidenterbackgroundnotification object:nil]; add function cater notification when posted
-(void)applicationenteredbackground { //do above steps here when want. } and in dealloc function of class remove observer notification
-(void)dealloc { [[nsnotificationcenter defaultcenter] removeobserver:self]; }
Comments
Post a Comment