Reputation: 504
I'm facing a problem with SimpleDateFormat
that's parsing a non date String.
Here's the code used reduced to minimum:
public class TestAddressAgainstDate {
public static void main(String[] args) throws ParseException {
SimpleDateFormat oFormat = new SimpleDateFormat( "yyyy-MM-dd" );
String m_sColumnValue = "3-21-1, Nihombashi Hama-Cho";
Date oDate = oFormat.parse( m_sColumnValue );
System.out.println(oDate);
}
}
the output is the following:
Mon Sep 01 00:00:00 CET 4
The code this is from is testing whether the String is a date or not as the processor is also receiving date Strings from an XML. My problem is that I can't change the behaviour of getting the field as String and I need to deal with also getting dates from.
Anyone has an idea on how to solve this?
The original idea was to catch the ParseException and deal it as not a date but the japanese address ruined it. :-)
Thanks in advance
EDIT:
I have another string which is causing problems even with setLenien(false)
.
String m_sColumnValue = "1-5-1 Ohtemachi, Chiyoda-Ku4";
anyone an Idea?
Upvotes: 3
Views: 145
Reputation: 159784
Use setLenient
to verify the input date String
oFormat.setLenient(false);
Upvotes: 5