File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "about "Date" class" Watch "about "Date" class" New topic

about "Date" class

Wang Kaiyi

Joined: Feb 02, 2004
Posts: 9
I am confused about "Date" class;
1. I don't know why there is another "Date" in package "java.sql" other than "java.util.Date".
2. And what's the difference between them?

3. In my eyes, the methods of "Date" such as "getDay" "getHours" is very useful, why it is deprecated?
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
java.sql.Date is a thin wrapper of a millisecond value, which enables JDBC to identify it as a SQL date. In the SQL specification there is no time component of a date value, so the hours, minutes, seconds and milliseconds must be zero. All the methods for getting and setting time e.g getHours are deprecated as they serve no purpose.
java.util.Date is a class that represents a specific moment in time, with millisecond precision. However it's methods for getting and and setting date and time were not particulary conducive to internationalization and the java.util.Calender class should be used to convert between a date and it's various time fields i.e(YEAR, MONTH Also the java.util.DateFormat class should be used to format and parse date strings
best regards,
Nigel Browne
Wang Kaiyi

Joined: Feb 02, 2004
Posts: 9
thank you for your response!But I have a new problem.
I want a String as such format "2004-02-25 12:05:09".
which class and methods can I use?
I tried to do this as following:
java.util.Date dDate = new java.util.Date(System.currentTimeMillis());
String sDate = dDate.dDate.toLocaleString();
then, I execute my program....
the result:
sDate is "2004-02-25 12:05:09" in Windows Environment.(JBuilder9)
sDate is "Feb 25, 2004 12:05:09 AM" in Linux Environment.
I am very confused about this.
What difference can OS make???

and my Linux Environment is as following:
[ken@test47 consumer]$ java -version
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
[ken@test47 consumer]$ uname -a
Linux test47 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686 unknown
Zac Nahas

Joined: Feb 24, 2004
Posts: 6
I have also a question about the Date? I want to find the time between to events so I first use GetDate and then do some processing. Then do another GetDate. How do I find the time between the two events ie How do I subtract time?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You can say
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I agree. Here's the link:
subject: about "Date" class
It's not a secret anymore!