File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes how to cast the java.util.date to java.sql.date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "how to cast the java.util.date to java.sql.date" Watch "how to cast the java.util.date to java.sql.date" New topic
Author

how to cast the java.util.date to java.sql.date

lei zhang
Greenhorn

Joined: Sep 15, 2004
Posts: 14
how to cast the java.util.date to java.sql.date

please give me a help!



and i want to get the hours,seconds.


people laugh and people cry.some give up some always try.some say hi while some say bye.others may forget you but never i!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41634
    
  55
java.sql.Date extends java.util.Date. That means you can cast java.sql.Date to java.util.Date, but not the other way round.

Both classes have methods called getHours, getMinutes and getSeconds.


Ping & DNS - my free Android networking tools app
Abhijith Prabhakar
Ranch Hand

Joined: Dec 29, 2006
Posts: 56
Hope this helps

/**
* Returns the sql.Date for the given util.Date
*
* @param oDate util.Date object
* @return sql.Date
*/
public static java.sql.Date convertToSqlDate(java.util.Date oDate) {
return (new java.sql.Date(oDate.getTime()));
}

/**
* Returns the util.Date for the given sql.Date
*
* @param sqlDate sql.Date object
* @return util.Date
*/
public static java.util.Date convertToDate(java.sql.Date sqlDate) {
return (new java.util.Date(sqlDate.getTime()));
}
lei zhang
Greenhorn

Joined: Sep 15, 2004
Posts: 14
reply Abhijith Prabhakar :

thank you give me the methods to deal with this,but ,i do it like you say that,but i translate it in this way what you say,i didn't get the hours,minutes,and seconds only the day,month,and year ,can you tell me why?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41634
    
  55
What do you mean by "i didn't get the hours,minutes,and seconds"? The getHours, getMinutes and getSeconds methods must return something. If you mean that the return value is always zero, have you checked that the DB has the exact values for those fields?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to cast the java.util.date to java.sql.date