2

I am trying to convert sql date string to normal date, but I am getting this exception

java.text.ParseException: Unparseable date: "2013-03-11" at java.text.DateFormat.parse(Unknown Source) at com.ninenexus.simplesignworkflow.Task.getTaskDetails(Task.java:1385) at org.apache.jsp.task_jsp._jspService(task_jsp.java:259) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

I want like this

From "2013-03-11" to "11/03/2013" how can i FIX it?

9
  • 7
    java.sql.Date is a java.util.Date. Commented Apr 3, 2013 at 7:12
  • Post your code how you are trying to convert. As per the exception it seems your format is wrong. Commented Apr 3, 2013 at 7:12
  • look at stackoverflow.com/questions/2980583/… Commented Apr 3, 2013 at 7:13
  • i am fetching date from database, and converting it to normal. Commented Apr 3, 2013 at 7:13
  • 1
    new SimpleDateFormat("dd/MM/yyyy).format(new SimpleDateFormat("yyyy-MM-dd").parse("2013-03-11"))? Commented Apr 3, 2013 at 7:13

4 Answers 4

3

What you are doing is simply unreasonable.

First, java.sql.Date is already a java.util.Date.

Second, java.sql.Date is NOT a SQL date string. Both java.sql.Date and java.util.Date has nothing to do with the format how the date is going to be displayed. i.e. There is no such thing as a Date containing "2013-03-11" while another Date containing "11/03/2013".

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

Comments

3
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");  
String text = df.format(date);  

System.out.println("The date is: " + text); 

Comments

1

Try it in this way:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = df.parse("2013-03-11");   // convert string to date
df=new SimpleDateFormat("dd/MM/yyyy");
// date formatted in whatever format you want. 
System.out.println("The date is: " + df.format(date));

Comments

0

Take a help of SimpleDateFormat class and parse date string to get Util Date object.

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

    public class DateConverter {

        public static void main(String[] args) throws ParseException {

            String dateString = "03/04/2013";
            Date utiDate;
            SimpleDateFormat dateFormater = new SimpleDateFormat("dd/MM/yyyy");
            utiDate = dateFormater.parse (dateString);
            System.out.println(utiDate);
        }
    }

Comments

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.