• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Time class

 
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.
 
Rancher
Posts: 43009
76
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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:
 
(instanceof Sidekick)
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!