luckydexte
Programmer
Hello all,
I am running into a problem trying to insert 12:00 PM into a DB2 database TIME field. I have a jsp page that has a select box with the values 1:00 to 12:00 and a select box with the values of AM and PM. I am using SimpleDateFormat and everything works with the exception of 12:00 PM. 12:00AM and 12:00PM both are inserted as 00:00:00.
My code is below. Any help would be greatly appreciated.
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
String time;
int var = Integer.valueOf(s); // s will be 1 through 12
if (ap.equals("AM")) {
if (var == 12)
time = "00:00:00";
else
time = s + ":00:00";
}
else {
if (var == 12) {
time = "12:00:00";
}
else {
var = var + 12;
time = var + ":00:00";
}
}
try {
return sdf.parse(time);
}
catch (Exception e){
return new Date();
}
Thanks,
Brandon
I am running into a problem trying to insert 12:00 PM into a DB2 database TIME field. I have a jsp page that has a select box with the values 1:00 to 12:00 and a select box with the values of AM and PM. I am using SimpleDateFormat and everything works with the exception of 12:00 PM. 12:00AM and 12:00PM both are inserted as 00:00:00.
My code is below. Any help would be greatly appreciated.
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
String time;
int var = Integer.valueOf(s); // s will be 1 through 12
if (ap.equals("AM")) {
if (var == 12)
time = "00:00:00";
else
time = s + ":00:00";
}
else {
if (var == 12) {
time = "12:00:00";
}
else {
var = var + 12;
time = var + ":00:00";
}
}
try {
return sdf.parse(time);
}
catch (Exception e){
return new Date();
}
Thanks,
Brandon