# Dividing Time into equal intervals

kittu shusma
Greenhorn
Posts: 14
Hi,

i have given start time and end time,
the difference between start time and end time i got some x time,
i have to split that time into 50 min segments of timesolts.
for example...
8.30 - 12.00 = 3.30,
this 3.30 min can be divided into 50 min of timesolts like this format,
8.30
9.20
10.10
11.00
11.50....
can you help to me solve this problem.

Thanks,
Kittushusma.

Winston Gutkowski
Bartender
Posts: 10527
64
kittu shusma wrote:i have given start time and end time,
the difference between start time and end time i got some x time,
i have to split that time into 50 min segments of timesolts.

I'm not quite sure what you're asking. A Java Date (which can be obtained from a Java GregorianCalendar) is simply a number of milliseconds from the a fixed point in time (called the 'epoch'). You can therefore get the difference between two Dates in milliseconds, after which it's simple a matter of division to get the minutes.

Does that help?

Winston

Randall Twede
Ranch Hand
Posts: 4489
3
you need to change 3.30 to 210 minutes

Michael Dunn
Ranch Hand
Posts: 4632
What does deducting start time from
end time have to do with anything?

startTime + 50mins = newTime
newTime + 50mins = anotherNewTime
repeat until endTime

kittu shusma
Greenhorn
Posts: 14
i just given the start time,end time and class duration..
can you please send to me that logic...

Michael Dunn
Ranch Hand
Posts: 4632
> can you please send to me that logic...

most of it is in the earlier post.

start by creating a calendar object.
set the time to the start time
then (in a loop)
b) check if the new time is after the end time
if not
{
c) save the time/print it out/whatever
repeat above, in the loop
}
if it is after the end time
{
do nothing
break out of the loop
}

have a go, if you get stuck, post what you've tried.

Campbell Ritchie
Sheriff
Posts: 50666
83
What format are you storing those times in? When you write 8.30, how is it stored?

kittu shusma
Greenhorn
Posts: 14
I tried but am not getting proper out put,
can you please send me the code..

Steve Luke
Bartender
Posts: 4181
22
kittu shusma wrote:I tried but am not getting proper out put,
can you please send me the code..

Hi Kittu, that generally isn't how things work here (We are NotACodeMill). What we would prefer is that you show us your code which you tried to implement the above suggestions and tell us the part where you are having trouble. Then we can help you with the problems. So, can you show us your code?

Campbell Ritchie
Sheriff
Posts: 50666
83
What sort of format have you got those “times” in? Are they floating-point numbers? If so, you will find it dreadfully difficult to get the correct times from them.

kittu shusma
Greenhorn
Posts: 14
Hi,

I tried but am not getting proper out put,
i am sending the code is there any mistakes please correct me..

Michael Dunn
Ranch Hand
Posts: 4632
well, that code is a bit of a dog's breakfast.

why would you create all those things in each loop of a for loop?

to start, your SimpleDateFormat pattern is wrong - read what each part represents, you'll find the error

use 2 calendars start/end, setting them to the times you have
then, in a while() loop (not a for()), you check while(!startCal.after(endCal))//allows it to be equal,
and do 2 things (1) add to the arraylist (2) add 50 minutes.

when you have it working, you'll see how simple it is