tags:

views:

285

answers:

4

I want to accept a Date format according to an ISO (can't remember which one)...

2009-09-17T13:03:00

How do I do this? I'm currently using a SimpleDateFormat but when I run my unit test against it, it fails.

DateFormat df = SimpleDateFormat("yyyy-MM-ddTHH:mm:ss");

Unit Test is passing it this string:

String test1 = "2009-09-17T13:07:01";
+9  A: 

Hi,

The SimpleDateFormat parameter should be "yyyy-MM-dd'T'HH:mm:ss".

Regards.

ATorras
Thanks, man. I bloody knew it would be something simple!
day_trader
+4  A: 

Your format is wrong. It should be something like this,

SimpleDateFormat isoFormat = 
    new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
ZZ Coder
+1  A: 

An easy Solution is to remove the "T" ;-)

...      
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");

Date date = df.parse("2009-09-17T13:07:01".replace("T",""))

Regards, Jan

Jan
+5  A: 

You need to enclose the T in single quotes

Tarski
Again, I knew it would be something simple..
day_trader