I have 2 strings which are actually dates but they are in different format:
- 2004-06-01 00:00:00 (This value I get from Excel database through JDBC)
- 6/1/2004
Is their any pre-defined Class in Java which I can use to create Date kind of object? So that I can just invoke its constructor over these Strings and finally compare them.
Or will I have to write my own function to compare using String functions? Please Help.
Thanks for reading.
You are looking for SimpleDateFormat.
SimpleDateFormat is an implementation of the abstract DateFormat. You first define the pattern of the date in the constructor and then use parse method.
If you are using a Locale other than the default, you need to define it at the constructor.