ios - Detect which lesson is closest to now -


i'm having array different times of lessons. here's example kind of information array contains:

09.00 - 10.00, 11.00 - 12.00, 13.00 - 14.00, 15.00 - 16.00

i'm displaying these lessons in uipickerview in order let user choose desired time. want pickerview automatically preselect lesson closest actual time. somehow have compare actual date. has idea how that?

thanks in advance!

this give current hour:minutes

    nsdateformatter *dateformat = [[nsdateformatter alloc] init];     [dateformat setdateformat:@"hh:mm"];     nsstring *str = [dateformat stringfromdate:[nsdate date]]; 

then can find difference , check minimum.

now can put condition :

if      (hh <= 10 )            { // 09:00 - 10:00 should come } else if (hh == 10 && mm < 30 ) { // 09:00 - 10:00 should come }  else if (hh == 10 && mm > 30 ) { // 11:00 - 12:00 should come } else if (hh <= 12 && mm < 30 ) { // 11:00 - 12:00 should come }  else if (hh == 14 && mm < 30 ) { // 13:00 - 14:00 should come } else if (hh <= 14 && mm > 30 ) { // 13:00 - 14:00 should come }  else if (hh == 14 && mm < 30 ) { // 15:00 - 16:00 should come } else if (hh <= 14 && mm > 30 ) { // 15:00 - 16:00 should come } else                           { // 15:00 - 16:00 should come } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -