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.  
shgjAsked:
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.

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

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

or

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
0

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.
0
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..
0
vivexpCommented:
Hi,

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



0
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()
    {
       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.}
0
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
Java

From novice to tech pro — start learning today.