Generating a list of Start Times and End Times in Java -
Generating a list of Start Times and End Times in Java -
i need generate list of start times , end times in java such that, end time greater start time , difference between start time , end time must maximum of 5 hours.
time format can of either 24 hours or 12 hours.
i tried code difference between start time , end time criteria not satisfied start times , end times:
         string mytime = "07:00:00";          simpledateformat df = new simpledateformat("hh:mm:ss");          date d = df.parse(mytime);           calendar cal1 = calendar.getinstance();          cal1.settime(d);          calendar cal2 = calendar.getinstance();          cal2.settime(d);          int i=10;           list<string> list3 = new arraylist<string>();          list<string> list4 = new arraylist<string>();            while(i<50)          {               cal1.add(calendar.minute, i);              string start_time = df.format(cal1.gettime());              cal2.add(calendar.second, i);              string end_time = df.format(cal2.gettime());              list3.add(start_time);              list4.add(end_time);              i=i+1;          }             file file = new file("output9.txt");             fileoutputstream fos = new fileoutputstream(file);             printstream ps = new printstream(fos);             system.setout(ps);             (int j = 0,k=0;j < list3.size()&&k<list4.size(); j++,k++) {                 string value3 = list3.get(j);                 string value4 = list4.get(k);                 system.out.println("\n");                 system.out.printf("%s%s%s",value3," ",value4);             }    could please help me how it?
thanks in advance...
i guess problem in add-on of starttimes. add together n minutes starttime, add together amount seconds of endtime.
so schould  alter  next int while:
cal1.add(calendar.minute, i); string start_time = df.format(cal1.gettime()); cal2.add(calendar.minute, i); //  add together line cal2.add(calendar.second, i); string end_time = df.format(cal2.gettime());    if want real random ranges, accomplish setting start random time, save string array , add together amount of time between 0 , 5 hours , add together end array.
edit illustration random ranges
random rand = new random(); simpledateformat df = new simpledateformat("hh:mm:ss"); calendar calendar = calendar.getinstance();  list<string> starttimes = new arraylist<string>(); list<string> endtimes = new arraylist<string>();  (int = 0; < 50; i++) {     calendar.set(calendar.hour_of_day, 7 + rand.nextint(7)); // starting @ 07:00:00     calendar.set(calendar.minute, rand.nextint(60));     calendar.set(calendar.second, rand.nextint(60));     string start_time = df.format(calendar.gettime());      calendar.add(calendar.hour, rand.nextint(5));     calendar.add(calendar.minute, rand.nextint(60));     calendar.add(calendar.second, rand.nextint(60));     string end_time = df.format(calendar.gettime());     starttimes.add(start_time);     endtimes.add(end_time); }    this generate 50 starttimes 7 14 , endtimes maximum of 5 hours longer. example:
[13:38:56, 08:32:57, 08:50:15, 07:10:49, 13:48:06] [13:45:53, 08:36:29, 12:16:35, 11:19:06, 17:19:36]        java 
 
Comments
Post a Comment