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
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