java - Adding minutes to Calendar object -
i attempting add amount of time calendar object. input coming time picker , output goes 2 strings.
dateformat dateformat = new android.text.format.dateformat(); calendar starttimecalendar = calendar.getinstance(); //these 2 string this: "08:15am" int prevstarthour = integer.parseint(starttime.gettext().subsequence(0, 2).tostring()); int prevstartminute = integer.parseint(starttime.gettext().subsequence(3, 5).tostring()); int prevendhour = integer.parseint(endtime.gettext().subsequence(0, 2).tostring()); int prevendminute = integer.parseint(endtime.gettext().subsequence(3, 5).tostring()); //get difference in hours between 2 strings int hourchange = math.abs(prevendhour - prevstarthour); //get difference in minutes between 2 strings int minutechange = math.abs(prevendminute - prevstartminute); //set date on first label starttime.settext(dateformat.format("hh:mmaa", starttimecalendar).tostring()); //add difference in hours calendar starttimecalendar.add(calendar.hour_of_day, hourchange); //add difference in minutes calendar starttimecalendar.add(calendar.minute, minutechange); //set date on second label endtime.settext(dateformat.format("hh:mmaa", starttimecalendar).tostring());
now odd part... hours add fine , dandy while minutes decide stop working halfway through. instead of adding expected time (be 15, 30 or 45min) adds 30min every time.
change hh:mmaa
hh:mmaa
(link).
Comments
Post a Comment