Problems Formatting Date

Hi,

I cannot seem to get the date to format correctly.

I initially have: 2007-04-11

I want to have: 4/11/2007 4:00:00 PM

Here is what I am doing:

DateFormat dateFormatA =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

DateFormat dateFormatB =new SimpleDateFormat("M/d/yyyy h:mm:ss a");

dateFormatB.setLenient(false);

date = dateFormatA.parse(date.toString() +" " + crsCapacity.getString("Hour") +":00:00");

date = dateFormatB.parse(dateFormatB.format(date));

But I cannot get the correct format to appear.

I get Wed Mar 21 16:00:00 EDT 2007.

dateFormatB.format(date) works fine. It ouputs exactly what I want but as a String. I need to use this String to update a Timestamp field in a DB.

Any help will be greatly appreciated.

Thanks!

[1050 byte] By [bce_developera] at [2007-11-27 0:44:07]
# 1
> date = dateFormatB.parse(dateFormatB.format(date))You probably don't want to parse this again. Just dateFormatB.format(...)
tjacobs01a at 2007-7-11 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 2
But that returns a string and when I callcrsResults.updateTimestamp("DateTime", dateFormatB.format(date));will throw an error because its not a Timestamp object
bce_developera at 2007-7-11 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 3

You want a java.util.Timestamp. Create one using one of the following

[url=http://java.sun.com/javase/6/docs/api/java/sql/Timestamp.html#Timestamp(long)]Timestamp(long)[/url]

[url=http://java.sun.com/javase/6/docs/api/java/sql/Timestamp.html#valueOf(java.lang.String)]Timestamp.valueOf(String)[/url]

DrLaszloJamfa at 2007-7-11 23:06:45 > top of Java-index,Java Essentials,Java Programming...