Java.sql.date extends java.util.date, so is it save to convert between the two by casting a java.sql.date as a java.util.date? Or is there some other way to convert them?
sql. Date just represent DATE without time information while java. util. Date represents both Date and Time information.
util. Date (just Date from now on) is a terrible type, which explains why so much of it was deprecated in Java 1.1 (but is still being used, unfortunately). Design flaws include: Its name is misleading: it doesn't represent a Date , it represents an instant in time.
You don't necessarily need to cast, you can just treat a SQL Date as if it was a util Date:
java.sql.Date sqlDate = new java.sql.Date(whenever);
java.util.Date utilDate = sqlDate;
Compiles and runs just fine.
Yes, you can just upcast it.
The java.sql.Date
is in fact nothing less or more than a representation of the SQL Date type, which has only year, month and day filled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With