[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Java Date Type

Posted on 2000-01-21
6
Medium Priority
?
217 Views
Last Modified: 2010-04-01
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.  
0
Comment
Question by:shgj
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:vivexp
ID: 2373774
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
 
LVL 1

Accepted Solution

by:
vivexp earned 200 total points
ID: 2373828
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
 

Author Comment

by:shgj
ID: 2376644
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:shgj
ID: 2376667
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
 
LVL 1

Expert Comment

by:vivexp
ID: 2376756
Hi,

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



0
 

Author Comment

by:shgj
ID: 2377066
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question