• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dividing Time into equal intervals

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to change 3.30 to 210 minutes
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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)
a) add 50 minutes
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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What format are you storing those times in? When you write 8.30, how is it stored?
 
kittu shusma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried but am not getting proper out put,
can you please send me the code..
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic