Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

java.lang.IllegalArgumentException SimpleDateFormat java

java.lang.IllegalArgumentException SimpleDateFormat java

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
abostasia



Joined: 24 Dec 2008
Posts: 1

PostPosted: Thu Feb 05, 2009 7:16 am    Post subject: java.lang.IllegalArgumentException SimpleDateFormat java Reply with quote

Hi,

I am trying to parse date format into my required format. Every thing is done according proper format but still it is getting exception of simpleDateFormat .
Quote:

Exception in thread "main" java.lang.IllegalArgumentException
at java.util.Date.parse(Unknown Source)
at java.util.Date.<init>(Unknown Source)
at DateCheck.main(DateCheck.java:Cool


This error is coming in my program.

my code is like

Code:
import java.util.Date;
import java.text.SimpleDateFormat;
public class DateCheck {
   public static void main(String[] args) {
        String dDate="12-09-2009";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date cDate=new Date(dDate);
        String sFormatted=sdf.format(cDate);
        System.out.println("Date :"+sFormatted);
   }
}


Please tell me how to change format of date with simpledateformat in java
Back to top
View user's profile Send private message
seniormember
Site Admin


Joined: 20 Jul 2008
Posts: 77

PostPosted: Thu Feb 05, 2009 7:23 am    Post subject: Reply with quote

Quote:
java.lang.IllegalArgumentException


In SimpleDateFormat means you are not passing corrent delimiter in date format. "-" is not corrent delimiter for sending date to
Quote:
Date cDate=new Date(dDate);


this needs / only and date format should be

"mm/dd/yyyy"

wrong date
String dDate="12-09-2009";

correct date
String dDate="12/29/2009";

try this code
Code:

import java.util.Date;
import java.text.SimpleDateFormat;
public class DateCheck {
   public static void main(String[] args) {
        String dDate="12/09/2009";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date cDate=new Date(dDate);
        String sFormatted=sdf.format(cDate);
        System.out.println("Date :"+sFormatted);
   }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack