aspose file tools*
The moose likes Beginning Java and the fly likes Parsing date..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Parsing date..?" Watch "Parsing date..?" New topic
Author

Parsing date..?

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 244

hi,
I my form i am using jquery date picker and it gives date of formate "dd/mm/yyyy" the value is passed to servlet and i have to insert it into mySQL Db so i write faloowing code.



it is giving Exception like

  • java.text.ParseException: Unparseable date: "29/11/2011"
    at java.text.DateFormat.parse(DateFormat.java:337)
    at com.garnet.jobseeker.JobSeekerServlet.getGeneralInfoArguments(JobSeekerServlet.java:150)
    at com.garnet.jobseeker.JobSeekerServlet.doGet(JobSeekerServlet.java:79)
    at com.garnet.jobseeker.JobSeekerServlet.doPost(JobSeekerServlet.java:48)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Unknown Source)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

  • please help me
    John Jai
    Bartender

    Joined: May 31, 2011
    Posts: 1776
    For the string "29/11/2011" shouldn't the format be "dd/MM/yyyy"?
    mallikarjun dontamsetti
    Ranch Hand

    Joined: Mar 18, 2011
    Posts: 244

    John Jai wrote:For the string "29/11/2011" shouldn't the format be "dd/MM/yyyy"?


    I want the formate as "yyyy-MM-dd"(mySQL formate) for the above string.
    John Jai
    Bartender

    Joined: May 31, 2011
    Posts: 1776
    Use parse() method first to convert the input string into date and then format it into required format using the format() method - SimpleDateFormat
    Harsha Smith
    Ranch Hand

    Joined: Jul 18, 2011
    Posts: 287
    The following code should give you some idea on how to do it.

    John Jai
    Bartender

    Joined: May 31, 2011
    Posts: 1776
    I usually do that using two formatters... I don't know if this is efficient though..

    mallikarjun dontamsetti
    Ranch Hand

    Joined: Mar 18, 2011
    Posts: 244

    John jai, Harsha Smith thaanks...
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Parsing date..?