Link to home
Start Free TrialLog in
Avatar of shgj
shgj

asked on

Java Date Type

How to transfer a String type value to a Date type value(java.sql.Date & java.util.Date), and how to judge a value whether is a Date type , and which difference between java.sql.Date and java.Util.Date.  
Avatar of vivexp
vivexp

Hi
the difference betn java.sql.Date  and java.Util.Date.  
 java.sql.Date
A thin wrapper around a millisecond value that allows JDBC to identify this as a SQL DATE. A milliseconds value represents the
number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.

To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by
setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

 java.Util.Date.
The class Date represents a specific instant in time, with millisecond precision. Prior to JDK 1.1, the class Date had two additional functions. It allowed the interpretation of dates as year, month, day, hour,
minute, and second values.
ASKER CERTIFIED SOLUTION
Avatar of vivexp
vivexp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shgj

ASKER

I want to generate a new class, and this class extends this java.util.Date class, but I will new some method, for example transfer a value from String to Date, and judge a value if is a Date type.
Avatar of shgj

ASKER

I generate a new class, and this class extends Date class , in new class, i new some method, at public method strToDate, i use Date.Parse("1999-01-02"), but always throws IllAligement..
Hi,

Is it throwing an exception?
IF yes, what is the exception?



Avatar of shgj

ASKER

Hi vivexp,
  Yes, it is IllegalArgumentException exception.

the following is code:


package inet.library;
import java.util.Date;

public class NCSDate extends Date
{  

    public NCSDate()
    {
       super(System.currentTimeMillis());
    }
    public NCSDate(int year, int month, int date)
    {
        super(year, month, date, 0, 0, 0);
    }
    public NCSDate(int year, int month, int date, int hrs, int min)
    {
        super(year, month, date, hrs, min, 0);
    }
    public NCSDate(String s)
    {
        super(parse(s));
    }
    public NCSDate StrToDate(String strDate)
    {
//try
//{
//Date.parse(strDate)
//}catch(IllegalArgumentException e)
//{}


//here, will converse the String to Date, but I want to return a NCSDate value.////I don't know how to do it, thank you for helping me.}