Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

Can I Convert Calendar date to yyyy-MM-dd format in java?

Asked by Nisha Arti Mar 25, 2021 1.3K views 1 answer
Share

About this question

How to convert calendar date to yyyy-MM-dd format.

Calendar cal = Calendar.getInstance();

cal.add(Calendar.DATE, 1);

Date date = cal.getTime();             

SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

String date1 = format1.format(date);            

Date inActiveDate = null;

try {

    inActiveDate = format1.parse(date1);

} catch (ParseException e1) {

    // TODO Auto-generated catch block

    e1.printStackTrace();

}

This will produce inactive date = Wed Sep 26 00:00:00 IST 2012. But what I need is 2012-09-26. My purpose is to compare this date with another date in my database using Hibernate criteria. So I need the date object in yyyy-MM-dd format.

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.