S
Steve Austin
Hi can you assist me in finding the root cause of this problem. I am
converting a simple date of "2007-04-20" to SQL date. However for
some reason the conversion is not working. It seems to be defaulting
too 2007-01-20. Hmm.. perhaps its the getTime() not returning the
correct number of milliseconds since January 1, 1970. Not sure.
Anyway would appreciate a secound pair of eyes on this one. Thanks
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
//The code
public class Testing {
public static void main(String[] args) {
try {
SimpleDateFormat formater = new SimpleDateFormat("yyyy-mm-
dd");
String inDateClaimed = "2007-04-20";
java.util.Date parsedDate = formater.parse(inDateClaimed);
System.out.println("inDateClaimed=" +inDateClaimed);
Date result = new java.sql.Date(parsedDate.getTime());
System.out.println("result=" +result);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
//The Output
inDateClaimed=2007-04-20
result=2007-01-20
converting a simple date of "2007-04-20" to SQL date. However for
some reason the conversion is not working. It seems to be defaulting
too 2007-01-20. Hmm.. perhaps its the getTime() not returning the
correct number of milliseconds since January 1, 1970. Not sure.
Anyway would appreciate a secound pair of eyes on this one. Thanks
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
//The code
public class Testing {
public static void main(String[] args) {
try {
SimpleDateFormat formater = new SimpleDateFormat("yyyy-mm-
dd");
String inDateClaimed = "2007-04-20";
java.util.Date parsedDate = formater.parse(inDateClaimed);
System.out.println("inDateClaimed=" +inDateClaimed);
Date result = new java.sql.Date(parsedDate.getTime());
System.out.println("result=" +result);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
//The Output
inDateClaimed=2007-04-20
result=2007-01-20