• Post Reply Bookmark Topic Watch Topic
  • New Topic

time comparison between given periods  RSS feed

 
Anuranjan Arya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
I want to to check whether a given time lies between a given periods of time.
for example

whether 11:45:00 lies between 11:00:00 and 12:00:00.

Can any 1 tell me, how can i achieve this in java?

Thank you
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the classes which represent time, and which implement the Comparable interface. For time try java.util.Date and java.util.Calendar (or its concrete subtypes) or google for Yoda Time or google for Apache commons and look there for time classes; the inbuilt Java classes are (some people believe) poorly designed. You can create objects representing your times mentioned (which require a date as well as a time) then if compareTo returns -1 for the lower bound or 1 for the higher bound you know your time isn't in that period. Or vice versa.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, it's not "any 1": read this.
 
sachin burange
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to Use Calendar methods:


public abstract boolean equals(Object obj)
public abstract boolean after(Object when)
public abstract boolean before(Object when)


 
Anuranjan Arya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sachin your reply solved me probem
 
Venkata Krishn Rao Maddu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the following example,

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!