java.util.Date - Contains date and time.
java.sql.Date - Contains only date (no time) - It sets the time component to 0.
If you have a situation where you're doing something like new Date(), in your TO (or anywhere else) and are concerned about the time component, you must use java.util.Date. While storing it in the database, you would want to use java.sql.Timestamp.
If this is not the case, and you only require the date part and are not interested in the time, java.sql.Date is fine.
I hope these points can help you take a decision on whether to use sql date or util date in any class anywhere (not just TO's).
Run this piece of code to see what I mean
public class test {
public static void main(String[] args) {
System.out.println(new Date());
System.out.println(new java.sql.Date(System.currentTimeMillis()));
}
}
java.util.Date v/s java.sql.Date
Labels: Do You Know ?
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment