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.  
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the difference betn java.sql.Date  and java.Util.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.

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.
use this function defined in class DateFormat
public Date parse(String text)
           throws ParseException

     Parse a date/time string.
          text - The date/time string to be parsed
          A Date, or null if the input could not be parsed


public Date(String s)

     Deprecated. As of JDK version 1.1, replaced by DateFormat.parse(String s).

     Allocates a Date object and initializes it so that it represents the date and time indicated by the string s, which is interpreted
     as if by the parse(java.lang.String) method.

try it

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shgjAuthor Commented:
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.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

shgjAuthor Commented:
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..

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

shgjAuthor Commented:
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()
    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)
    public NCSDate StrToDate(String 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.}
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.