Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleDateFormatter won't parse!

Hello I am trying to use the SimpleDateFormatter to parse the date Wed, 30 Jun 2010 15:07:06 CST

I am using the following code

public static SimpleDateFormat postedformat = 
    new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
Date newDate = new Date(posteformat.parse("Wed, 30 Jun 2010 15:07:06 CST"));

but I am getting an illegalArgumentException. Please help!

like image 501
Nathan Schwermann Avatar asked Apr 15 '26 21:04

Nathan Schwermann


2 Answers

postedformat.parse() returns a Date, and there is no Date(Date) constructor.

Presumably removing the call to new Date, so you say Date newDate = poste.... will suffice

like image 101
Noel M Avatar answered Apr 17 '26 09:04

Noel M


Your code fragment doesn't compile. This slight modification compiles and parses successfully:

public static void main(String[] args) throws ParseException {
    SimpleDateFormat postedformat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
    Date newDate = postedformat.parse("Wed, 30 Jun 2010 15:07:06 CST");
    System.out.println("newDate = " + newDate);
}

This is using Java 6 on Mac OS X.

like image 22
Steve McLeod Avatar answered Apr 17 '26 10:04

Steve McLeod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!