• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time class  RSS feed

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I'm looking for a class to manipulate time.

Example, time=12:50 add/subtract 30 min.
or return true if 11:50 is between 08:00 and 15:30

thanks for any pointers.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use the Date class, and convert the values to milliseconds be using the getTime method. That makes comparisons like these quite easy. If you're looking for something more elaborate, have a look at the JodaTime library.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the Date class as Ulf suggests, but the Calendar class might be more suitable - it has methods to do calculations with dates and times. For example, to add 30 minutes:
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For grins, look at a couple open source packages - Google JODA and TimeAndMoney - to see if they handle time intervals more sensibly.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.
I decided to use "Calendar". this solves the problem.
I took a look at JODA and it seems great (but not in this simple case)

thank a lot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!