35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
|
|
|
38 |
package java.sql; |
package java.sql; |
39 |
|
|
40 |
import java.text.SimpleDateFormat; |
import java.text.SimpleDateFormat; |
45 |
* |
* |
46 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
47 |
*/ |
*/ |
48 |
public class Date extends java.util.Date |
public class Date extends java.util.Date |
49 |
{ |
{ |
50 |
|
static final long serialVersionUID = 1511598038487230103L; |
51 |
|
|
52 |
/* |
/** |
53 |
* Class Variables |
* Used for parsing and formatting this date. |
54 |
*/ |
*/ |
55 |
|
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
56 |
/** |
|
57 |
* Used for parsing and formatting this date. |
/** |
58 |
*/ |
* This method initializes a new instance of this class with the |
59 |
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
* specified year, month, and day. |
60 |
|
* |
61 |
/** |
* @param year The year of this date minue 1900. |
62 |
* This is the serialization UID for this class. |
* @param month The month of this date (0-11). |
63 |
*/ |
* @param day The day of this date (1-31). |
64 |
private static final long serialVersionUID = 1511598038487230103L; |
* |
65 |
|
* @deprecated |
66 |
/*************************************************************************/ |
*/ |
67 |
|
public Date(int year, int month, int day) |
68 |
/* |
{ |
69 |
* Class Methods |
super(year, month, day); |
70 |
*/ |
} |
71 |
|
|
72 |
/** |
/** |
73 |
* This method returns a new instance of this class by parsing a |
* This method initializes a new instance of this class with the |
74 |
* date in JDBC format into a Java date. |
* specified time value representing the number of seconds since |
75 |
* |
* Jan 1, 1970 at 12:00 midnight GMT. |
76 |
* @param str The string to parse. |
* |
77 |
* |
* @param time The time value to intialize this date to. |
78 |
* @return The resulting <code>java.sql.Date</code> value. |
*/ |
79 |
*/ |
public Date(long date) |
80 |
public static Date |
{ |
81 |
valueOf(String str) |
super(date); |
82 |
{ |
} |
83 |
try |
|
84 |
{ |
/** |
85 |
java.util.Date d = (java.util.Date)sdf.parseObject(str); |
* This method returns a new instance of this class by parsing a |
86 |
return(new Date(d.getTime())); |
* date in JDBC format into a Java date. |
87 |
} |
* |
88 |
catch(Exception e) |
* @param str The string to parse. |
89 |
{ |
* @return The resulting <code>java.sql.Date</code> value. |
90 |
return(null); |
*/ |
91 |
} |
public static Date valueOf(String str) |
92 |
|
{ |
93 |
|
try |
94 |
|
{ |
95 |
|
java.util.Date d = (java.util.Date) sdf.parseObject(str); |
96 |
|
return(new Date(d.getTime())); |
97 |
|
} |
98 |
|
catch(Exception e) |
99 |
|
{ |
100 |
|
return(null); |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
|
/** |
105 |
|
* This method returns this date in JDBC format. |
106 |
|
* |
107 |
|
* @return This date as a string. |
108 |
|
*/ |
109 |
|
public String toString() |
110 |
|
{ |
111 |
|
return(sdf.format(this)); |
112 |
|
} |
113 |
} |
} |
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Constructors |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* This method initializes a new instance of this class with the |
|
|
* specified year, month, and day. |
|
|
* |
|
|
* @param year The year of this date minue 1900. |
|
|
* @param month The month of this date (0-11). |
|
|
* @param day The day of this date (1-31). |
|
|
* |
|
|
* @deprecated |
|
|
*/ |
|
|
public |
|
|
Date(int year, int month, int day) |
|
|
{ |
|
|
super(year, month, day); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method initializes a new instance of this class with the |
|
|
* specified time value representing the number of seconds since |
|
|
* Jan 1, 1970 at 12:00 midnight GMT. |
|
|
* |
|
|
* @param time The time value to intialize this date to. |
|
|
*/ |
|
|
public |
|
|
Date(long date) |
|
|
{ |
|
|
super(date); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Instance Methods |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* This method returns this date in JDBC format. |
|
|
* |
|
|
* @return This date as a string. |
|
|
*/ |
|
|
public String |
|
|
toString() |
|
|
{ |
|
|
return(sdf.format(this)); |
|
|
} |
|
|
|
|
|
} // class Date |
|
|
|
|