Top.Mail.Ru
March 16th, 2005 - Java developers — LiveJournal
? ?

Java developers

March 16th, 2005

12:37 am - valera - compiler hell

anyone get netbeans 4.1 beta? it looks nice.. and stuff, but i hate the fact that you need a project for everything!
what does everyone else think about this?
i need a compiler that has no problem with working without any silly project files. i can't be bothered to start a new project for every little thing i need to do!
i guess i could just use the old(er) version of netbeans.. anyone have any other ideas?

11:22 am - theycallmesir - date formating

I'm sure I'm making this overly complicated, but I could use some input.

I'm getting the current date with the following code...
// Get date
SimpleDateFormat sdf = new SimpleDateFormat(CONSTANTS.DATE_FORMAT);
Calendar cal = Calendar.getInstance();
String displayDate = sdf.format(cal.getTime());

When prompted I need to compare displayDate to the current date so that I can say "these dates are X hours apart". My problem is since displayDate is a String, I can't convert it to say millisecs to do the comparison.

Any suggestions?

Thanks

03:32 pm - theycallmesir - Thanks

I got the date format to work by using parts of your advice, here it is.

public long compareDates(String date1, String date2)
{
SimpleDateFormat sdf = new SimpleDateFormat();
long timeDiff = 0;

try
{
sdf.applyLocalizedPattern("yyyy-MM-dd HH:mm");
Date cal1 = sdf.parse(date1);

sdf.applyLocalizedPattern(CONSTANTS.DATE_FORMAT);
Date cal2 = sdf.parse(date2);

timeDiff = cal2.getTime() - cal1.getTime();

}
catch (ParseException pe)
{
String Message = pe.getMessage();
}

return timeDiff;
} // end of compareDates()

thanks for the help
Powered by LiveJournal.com