aspose file tools*
The moose likes Beginning Java and the fly likes compare dates for equality with a few minutes of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compare dates for equality with a few minutes of "leniency"" Watch "compare dates for equality with a few minutes of "leniency"" New topic
Author

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

Ben David
Ranch Hand

Joined: Oct 01, 2010
Posts: 67
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 01, 2010
Posts: 67
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

Joined: Jan 10, 2002
Posts: 61066
    
  66

Look closer.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben David
Ranch Hand

Joined: Oct 01, 2010
Posts: 67
dur..... I should have seen that!!
sandy chops
Greenhorn

Joined: Nov 11, 2010
Posts: 8
check getTime() , Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
 
 
subject: compare dates for equality with a few minutes of "leniency"