Hello, I'm recieving a date as a string through my main method. How do I cast this string to a date object to be compared to another date object in the class?
I wrote a CustomDate class which handled conversion between Strings and Dates. Here is the code for returning dates from strings, and strings from dates. I think the setDate method throws the parsing error if the String parameter is something other than a date.
Dorothy
***********************
import java.text.SimpleDateFormat
import java.text.ParseException;
import java.util.Date;
public static String getDate(java.util.Date d, String type) {
SimpleDateFormat formatter = null;
type = type.toUpperCase();
try {
if("L".equals(type)) {
formatter = new SimpleDateFormat("yyyy-MM-
if(DEBUG_ON) System.out.println("Long chosen.");
}
else if("S".equals(type)) {
formatter = new SimpleDateFormat("MM/dd/yy
if(DEBUG_ON) System.out.println("Short chosen.");
}
return(formatter.format(d)
} catch(Exception ex) {
ex.printStackTrace();
}
public static java.util.Date setDate(String s, String type) {
SimpleDateFormat formatter = null;
type = type.toUpperCase();
try {
if("L".equals(type)) {
formatter = new SimpleDateFormat("yyyy-MM-
}
else if("S".equals(type)) {
formatter = new SimpleDateFormat("MM/dd/yy
}
return(formatter.parse(s))
} catch(Exception pe) { ex.printStackTrace(); }
}