Format Time to Time/ Date to Date

Hi,

need some help. I try to format a Time and a Date value, but I don't want to convert them to a String.

I know this:

SimpleDateFormat formatDate = new SimpleDateFormat( "dd/MM/yyyy" );

SimpleDateFormat formatTime = new SimpleDateFormat( "HH:mm:ss" );

String strDate = formatDate.format( new Date() );

String strTime = formatTime.format( new Date() );

But instaed of "String strDate" and "String strTime" I want something like "Date dDate" and "Time tTime".

Do someone know, if it's possible?

Thanks in advance for your help....

[600 byte] By [chrissi711] at [2007-9-30 13:39:31]
# 1
No. Dates/times are represented as a Date object which is the milliseconds since January 1, 1970, 00:00:00 GMT. To present the information in a usable manner, it must be formatted as a String.I suspect that this is not your real question; what are you trying to do?
ChuckBing at 2007-7-4 22:33:55 > top of Java-index,Administration Tools,Sun Connection...
# 2
Hi man,try to use the method parse of your object formatDate. Look, your string must bo formated like the pattern ok?Bye.Ramon Garcia
ramongarcia at 2007-7-4 22:33:55 > top of Java-index,Administration Tools,Sun Connection...
# 3

Hi ChuckBing,

I have to insert/update a Date field in a recordset in a MS Access database. The problem is that the date must be formatted (dd/MM/yyyy) and the time also (HH:mm) - without seconds.

I can do something like this:

String strInsert = "INSERT INTO table"

+ "( Date, Time ) "

+ "VALUES "

+ "( "

+ "#" + strDate + "#" + ", "

+ "'" + strTime + "'"

+ " )";

stmt = con.createStatement();

stmt.executeUpdate( strInsert );

And this:

String strUpdate = "UPDATE table"

+ "SET Time = '" + strTime + "'"

+ " "

+ "WHERE "

+ "Date = " + "#" + strDate + "#"

+ " AND "

+ otherCriteria;

stmt = con.createStatement();

stmt.executeUpdate( strUpdate );

But this solution is bad. And this:

ResultSet rs = stmt.executeQuery( aQuery );

rs.moveToInsertRow();

rs.updateString( "Datum", "#" + strDate+ "#"); // doesn't work

rs.updateString( "Kommt", "'" + strTime + "'" ); // doesn't work

rs.insertRow();

rs.moveToCurrentRow();

doesn't work, because I can't write a String into a Date field on this way.

Do you know, what I'll try to explain?

chrissi711 at 2007-7-4 22:33:55 > top of Java-index,Administration Tools,Sun Connection...
# 4
you could use a prepared statement and the updateDate method instead...
jsalonen at 2007-7-4 22:33:55 > top of Java-index,Administration Tools,Sun Connection...