• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compare dates for equality with a few minutes of "leniency"

 
Ben David
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically I am trying to write something to compare a bunch of recording files with date and time int he file name, to a spreadsheet of calls.

I plan to match based on phone number and date/time of call. But the time on the recording and the time in the spreadsheet are bound to be off by up to a few minutes.

Does the compareTo method on java.util,date return a value based on the amount of difference or does it just return -1,0,1?

 
Paul Clapham
Sheriff
Posts: 21153
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't specify either of those in the documentation, which is the only authority you should be relying on. However it shouldn't be too onerous for you to write a method which finds the absolute value of the difference between the internal long values.
 
Ben David
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good point. the long values are the seconds since "epoch" right? What is the easiest way to get the long values? I don't see a method on the Date Class to retrieve it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look closer.
 
Ben David
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dur..... I should have seen that!!
 
sandy chops
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check getTime() , Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic