SimpleDateFormat with Node.getNodeValue

M

Manuel

Hi all.

I have the strangest problem. When I run this test-program, all runs fine:

public static void main(String[] args) {
Date d = null;
try{
SimpleDateFormat sdf = new SimpleDateFormat( "MMM-dd HH:mm" );
d = sdf.parse( "Aug-26 20:15");
System.out.println( "Date is valid: " + d.toString() );
} catch( ParseException pe ){
pe.printStackTrace();
}
}

BUT: when I try to do the same thing using the string returned from
a DOM-Node (getNodeValue()), I get a ParseException...


private boolean collectDate( Node cell ){
if( cell == null )return false;
Node child = cell.getFirstChild();
if( child == null )return false;
String childName = child.getNodeName();
if( !childName.equals( "#text") ){
return collectDate( child );
}
String str = child.getNodeValue();
SimpleDateFormat sdf = new SimpleDateFormat( "MMM-dd HH:mm" );
Date d = null;
try{
d = sdf.parse( str );
DoSomething.with( d );
} catch ( ParseException pe ){
Log.error( "Could not parse date '" + str + "'" );
Log.error( pe );
return false;
}
}

Any ideas what could be going on?
Thank you very much.
Manoo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top