I have read various recommendations for DateFormat and SimpleDateFormat when dealing with JDBC and java.sql.Date. However, none of the methods in DateFormat or SimpleDateFormat seem to accept or return a java.sql.Date. Instead, they use a java.util.Date. So: 1) How does one work with a java.sql.Date in DateFormat and SimpleDateFormat? 2) Is there a simple way to convert between java.util.Date and java.sql.Date?
This is what I do now. If there's a better way, I'd love to see it... // eg. convert current date from java.util.Date ... java.util.Date utilDate = new java.util.Date(); // ... to java.sql.Date java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
BTW, since java.sql.Date extends java.util.Date, you can pass it to SimpleDateFormat just as you would a java.util.Date. I believe DateFormat is an abstract class so you really want to use SimpleDateFormat or another concrete DateFormat descendant class.
[This message has been edited by JUNILU LACAR (edited October 06, 2001).]
Thank you so much! Since both java.util.Date and java.sql.Date have a constructor that accepts milliseconds, and they both have the getTime() method that returns milliseconds, then that is the key to freely creating one from the other. It was staring me in the face the whole time. Thanks for your help.
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Gift giving made easy with the permaculture playing cards