3

Getting error

java.lang.IllegalArgumentException at java.util.Date.parse(Unknown Source) at java.util.Date.(Unknown Source)

Here is my java code

import java.util.Date; 

public class DateCheck { 
public static void main(String[] args) { 
    String dDate="Sat Apr 11 12:16:44 IST 2015"; 
    Date cDate=null; 
    cDate = new Date(dDate); 
} 
}

I am using java 1.6

3

2 Answers 2

9

You have to use the method parse() of an implementation class of DateFormat. The simplest way is using SimpleDateFormat.

String dDate="Sat Apr 11 12:16:44 IST 2015"; 
DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date cDate = df.parse(dDate); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try this code:

String dDate="Sat Apr 11 12:16:44 IST 2015"
DateFormat formatter = new SimpleDateFormat("d-MMM-yyyy,HH:mm:ss aaa");
Date date = formatter.parse(dDate);
System.out.println(date);

2 Comments

The format in your SimpleDateFormat does not seem to match the format of the string you are parsing.
@khelwood, yeah, your right! Sorry for that, just in hurry!

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.