posted 21 years ago
I managed to create a Timestamp object, the code of which is below.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
Calendar calendar =Calendar.getInstance();
calendar.set(Integer.parseInt((cpdt.substring(cpdt.lastIndexOf("/")+1,cpdt.indexOf(":")-2)).trim()),Integer.parseInt(cpdt.substring(cpdt.indexOf("/")+1,cpdt.lastIndexOf("/")))-1,Integer.parseInt(cpdt.substring(0,cpdt.indexOf("/"))));
calendar.set(Calendar.HOUR ,Integer.parseInt(cpdt.substring(cpdt.indexOf(":")-2,cpdt.indexOf(":")).trim()));
calendar.set(Calendar.MINUTE,Integer.parseInt(cpdt.substring(cpdt.lastIndexOf(":")-2,cpdt.lastIndexOf(":"))));
calendar.set(Calendar.SECOND,Integer.parseInt(cpdt.substring(cpdt.lastIndexOf(":")+1)));
calendar.set(Calendar.AM_PM,1);
class_variable_pdt = Timestamp.valueOf(sdf.format(calendar.getTime()));
I am able to add the same to the db. The problem i am now facing is that if i store the date as 05/05/2002 19:33:50 ,it stores the same as 2004-05-05 7:33:50 am,this is incorrect.
if i set the simpledateformat object to "yyyy-MM-dd hh:mm:ss a", the timestamp gives an error.
plz help