0

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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

but I needed to get an object and set its time to 00:00 to compare with another object.. I find the solution to this issue by using Calendar. I used Calendar.HOUR_OF_DAY. Thanks for your reply anyway..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.