Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

API methods for difference between two dates

 
Peter Braun
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somebody please tell me why don't create the Sun create methods for calculate difference between two dates? Days between two dates for example.

Thanks,
Peter
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why Sun didn't add that to the standard library. But calculating the difference between to dates is easy. You just look at the millisecond values of your two Date objects and subtract them - then you have the difference in milliseconds. It's straightforward to convert this to days (just divide by 24 * 60 * 60 * 1000, which is the number of milliseconds in one day).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic