lamostreta
lamostreta

Reputation: 2409

Java - Date formatting

In a table I have a date object. I want to compare this date object with the current date (after 00:00). My code is:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
String dateBufferString = format.format(date);
Date dateBuffer = format.parse(dateBufferString);

System.out.println("date: " + format.format(date));
System.out.println("dateBufferSTring " + dateBufferString);
System.out.println("dateBuffer: " + dateBuffer);

studentList = session.createCriteria(Student.class)
            .add(Restrictions.eq("graduationDate", dateBuffer)).list();

The output of this is:

date: 2012-03-07 00:00:00
dateBufferSTring 2012-03-07 00:00:00
dateBuffer: Wed Mar 07 00:00:00 EET 2012

But still the studentList returns 0. What is wrong with the above code? Is there any way to format a date without converting it to a String first by using SimpleDateFormat?

Upvotes: 0

Views: 1276

Answers (1)

Bozho
Bozho

Reputation: 597124

You have your Date object - no need to go through different formats.

Upvotes: 3

Related Questions