aspose file tools*
The moose likes Java in General and the fly likes comparing two different dates in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "comparing two different dates in java" Watch "comparing two different dates in java" New topic
Author

comparing two different dates in java

Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
hi
i have two date, one of type long (retrieved from file.lastModified()) and the other date is a String object.
i was trying to figure out exactly how to parse them to the same form and compre them. i need to know which is after the other.
i was looking at SimpleDateFormat, DateFormat and Date and yet i still didn't manage to do it.
any suggestions?

thanks,
Yotam
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Did you try the java.util.Calendar class?


Mohamed Sanaulla | My Blog
Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
i took a brief look at the API and it seems like it would do the job, only i now know we are instructed to use SimpleDateFormat
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14107
    
  16

DateFormat and SimpleDateFormat are for formatting java.util.Date objects into strings, or parsing strings back to Date objects. Those classes don't contain methods to compare dates.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
when you use a file.lastModified() method it returns a long value counting the time from 1970 or someting like that. is there any method you know
that can parse this long value into a date? i was looking for one but couldn't find it
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

Yotam Ohayon wrote:when you use a file.lastModified() method it returns a long value counting the time from 1970 or someting like that. is there any method you know
that can parse this long value into a date? i was looking for one but couldn't find it

How 'bout


SCJD 6, OCPJP7, Baroque Potion, G+
ashirvad jain
Ranch Hand

Joined: Nov 09, 2006
Posts: 50
Hi Yatom,

As david suggested,

# long millis = file.lastModified();
# Date touchedOn = new Date(millis);

Further more , you can use DateFormat, like below,

DateFormat format=DateFormat.getDateInstance(STYLE); // STYLE="HH:MM:SS " based on your requirement.
String fileDate=format.format(touchedOn );
fileDate.equals(DateToCompareWith);

I hope this will help you.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparing two different dates in java