datetime - How to generate time between given two range in android? -


i developing application in android. got stuck @ point:

user selects time range using spinner. displays times in between given range specific time interval. tried , came after 12 have print 1 in time unable do.adding example below.i don't know how implement it. example. if user selects 9-2 have generate like

9.00 9.30 10.00 10.30 11.00 11.30 12.00 12.30 1.00 1.30 2.00

can 1 me? idea enough. if need coding add here later.

here code generate time intervals int setted range. need call method timeintervalhelper.

here code:

public class timeintervalhelper {     public static void generatetimeinterval(final arraylist<string> intervals, final int starthour, final boolean isstarthalf, int endhour, final boolean isendhalf) {         final calendar calendar = calendar.getinstance();         calendar.set(calendar.hour, starthour);         calendar.set(calendar.minute, isstarthalf ? 30 : 0);         calendar.set(calendar.second, 0);         calendar.set(calendar.millisecond, 0);          endhour = endhour == 12 ? 0 : endhour;         while (calendar.get(calendar.hour) != endhour)             intervals.add(getinterval(calendar));         intervals.add(getinterval(calendar));          if (isendhalf)             intervals.add(getinterval(calendar));     }      public static void generatetimeinterval(final arraylist<string> intervals, final int starthour, int endhour) {         generatetimeinterval(intervals, starthour, false, endhour, false);     }      private static string getinterval(final calendar calendar) {         final string interval = string.format(                 "%d.%02d",                 calendar.get(calendar.hour) != 0 ? calendar.get(calendar.hour) : 12,                 calendar.get(calendar.minute)         );         calendar.add(calendar.minute, 30);         return interval;     } } 

here sample:

final arraylist<string> intervals = new arraylist<>(); timeintervalhelper.generatetimeinterval(intervals, 9, 2); // generate 9 2 timeintervalhelper.generatetimeinterval(intervals, 9, false, 2, true); // generate 9 2.30 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -