Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot insert 12:00 PM into database

Status
Not open for further replies.

luckydexte

Programmer
Apr 26, 2001
84
0
0
US
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
 
Problem solved. It was the format mask.

SimpleDateFormat("hh:mm:ss");

Needed to be:

SimpleDateFormat("HH:mm:ss");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top