src/share/classes/java/sql/Date.java

Print this page




  34  * To conform with the definition of SQL <code>DATE</code>, the
  35  * millisecond values wrapped by a <code>java.sql.Date</code> instance
  36  * must be 'normalized' by setting the
  37  * hours, minutes, seconds, and milliseconds to zero in the particular
  38  * time zone with which the instance is associated.
  39  */
  40 public class Date extends java.util.Date {
  41 
  42     /**
  43      * Constructs a <code>Date</code> object initialized with the given
  44      * year, month, and day.
  45      * <P>
  46      * The result is undefined if a given argument is out of bounds.
  47      *
  48      * @param year the year minus 1900; must be 0 to 8099. (Note that
  49      *        8099 is 9999 minus 1900.)
  50      * @param month 0 to 11
  51      * @param day 1 to 31
  52      * @deprecated instead use the constructor <code>Date(long date)</code>
  53      */

  54     public Date(int year, int month, int day) {
  55         super(year, month, day);
  56     }
  57 
  58     /**
  59      * Constructs a <code>Date</code> object using the given milliseconds
  60      * time value.  If the given milliseconds value contains time
  61      * information, the driver will set the time components to the
  62      * time in the default time zone (the time zone of the Java virtual
  63      * machine running the application) that corresponds to zero GMT.
  64      *
  65      * @param date milliseconds since January 1, 1970, 00:00:00 GMT not
  66      *        to exceed the milliseconds representation for the year 8099.
  67      *        A negative number indicates the number of milliseconds
  68      *        before January 1, 1970, 00:00:00 GMT.
  69      */
  70     public Date(long date) {
  71         // If the millisecond date value contains time info, mask it out.
  72         super(date);
  73 


 162         buf[2] = Character.forDigit((year/10)%10,10);
 163         buf[3] = Character.forDigit(year%10,10);
 164         buf[5] = Character.forDigit(month/10,10);
 165         buf[6] = Character.forDigit(month%10,10);
 166         buf[8] = Character.forDigit(day/10,10);
 167         buf[9] = Character.forDigit(day%10,10);
 168 
 169         return new String(buf);
 170     }
 171 
 172     // Override all the time operations inherited from java.util.Date;
 173 
 174    /**
 175     * This method is deprecated and should not be used because SQL Date
 176     * values do not have a time component.
 177     *
 178     * @deprecated
 179     * @exception java.lang.IllegalArgumentException if this method is invoked
 180     * @see #setHours
 181     */

 182     public int getHours() {
 183         throw new java.lang.IllegalArgumentException();
 184     }
 185 
 186    /**
 187     * This method is deprecated and should not be used because SQL Date
 188     * values do not have a time component.
 189     *
 190     * @deprecated
 191     * @exception java.lang.IllegalArgumentException if this method is invoked
 192     * @see #setMinutes
 193     */

 194     public int getMinutes() {
 195         throw new java.lang.IllegalArgumentException();
 196     }
 197 
 198    /**
 199     * This method is deprecated and should not be used because SQL Date
 200     * values do not have a time component.
 201     *
 202     * @deprecated
 203     * @exception java.lang.IllegalArgumentException if this method is invoked
 204     * @see #setSeconds
 205     */

 206     public int getSeconds() {
 207         throw new java.lang.IllegalArgumentException();
 208     }
 209 
 210    /**
 211     * This method is deprecated and should not be used because SQL Date
 212     * values do not have a time component.
 213     *
 214     * @deprecated
 215     * @exception java.lang.IllegalArgumentException if this method is invoked
 216     * @see #getHours
 217     */

 218     public void setHours(int i) {
 219         throw new java.lang.IllegalArgumentException();
 220     }
 221 
 222    /**
 223     * This method is deprecated and should not be used because SQL Date
 224     * values do not have a time component.
 225     *
 226     * @deprecated
 227     * @exception java.lang.IllegalArgumentException if this method is invoked
 228     * @see #getMinutes
 229     */

 230     public void setMinutes(int i) {
 231         throw new java.lang.IllegalArgumentException();
 232     }
 233 
 234    /**
 235     * This method is deprecated and should not be used because SQL Date
 236     * values do not have a time component.
 237     *
 238     * @deprecated
 239     * @exception java.lang.IllegalArgumentException if this method is invoked
 240     * @see #getSeconds
 241     */

 242     public void setSeconds(int i) {
 243         throw new java.lang.IllegalArgumentException();
 244     }
 245 
 246    /**
 247     * Private serial version unique ID to ensure serialization
 248     * compatibility.
 249     */
 250     static final long serialVersionUID = 1511598038487230103L;
 251 }


  34  * To conform with the definition of SQL <code>DATE</code>, the
  35  * millisecond values wrapped by a <code>java.sql.Date</code> instance
  36  * must be 'normalized' by setting the
  37  * hours, minutes, seconds, and milliseconds to zero in the particular
  38  * time zone with which the instance is associated.
  39  */
  40 public class Date extends java.util.Date {
  41 
  42     /**
  43      * Constructs a <code>Date</code> object initialized with the given
  44      * year, month, and day.
  45      * <P>
  46      * The result is undefined if a given argument is out of bounds.
  47      *
  48      * @param year the year minus 1900; must be 0 to 8099. (Note that
  49      *        8099 is 9999 minus 1900.)
  50      * @param month 0 to 11
  51      * @param day 1 to 31
  52      * @deprecated instead use the constructor <code>Date(long date)</code>
  53      */
  54     @Deprecated
  55     public Date(int year, int month, int day) {
  56         super(year, month, day);
  57     }
  58 
  59     /**
  60      * Constructs a <code>Date</code> object using the given milliseconds
  61      * time value.  If the given milliseconds value contains time
  62      * information, the driver will set the time components to the
  63      * time in the default time zone (the time zone of the Java virtual
  64      * machine running the application) that corresponds to zero GMT.
  65      *
  66      * @param date milliseconds since January 1, 1970, 00:00:00 GMT not
  67      *        to exceed the milliseconds representation for the year 8099.
  68      *        A negative number indicates the number of milliseconds
  69      *        before January 1, 1970, 00:00:00 GMT.
  70      */
  71     public Date(long date) {
  72         // If the millisecond date value contains time info, mask it out.
  73         super(date);
  74 


 163         buf[2] = Character.forDigit((year/10)%10,10);
 164         buf[3] = Character.forDigit(year%10,10);
 165         buf[5] = Character.forDigit(month/10,10);
 166         buf[6] = Character.forDigit(month%10,10);
 167         buf[8] = Character.forDigit(day/10,10);
 168         buf[9] = Character.forDigit(day%10,10);
 169 
 170         return new String(buf);
 171     }
 172 
 173     // Override all the time operations inherited from java.util.Date;
 174 
 175    /**
 176     * This method is deprecated and should not be used because SQL Date
 177     * values do not have a time component.
 178     *
 179     * @deprecated
 180     * @exception java.lang.IllegalArgumentException if this method is invoked
 181     * @see #setHours
 182     */
 183     @Deprecated
 184     public int getHours() {
 185         throw new java.lang.IllegalArgumentException();
 186     }
 187 
 188    /**
 189     * This method is deprecated and should not be used because SQL Date
 190     * values do not have a time component.
 191     *
 192     * @deprecated
 193     * @exception java.lang.IllegalArgumentException if this method is invoked
 194     * @see #setMinutes
 195     */
 196     @Deprecated
 197     public int getMinutes() {
 198         throw new java.lang.IllegalArgumentException();
 199     }
 200 
 201    /**
 202     * This method is deprecated and should not be used because SQL Date
 203     * values do not have a time component.
 204     *
 205     * @deprecated
 206     * @exception java.lang.IllegalArgumentException if this method is invoked
 207     * @see #setSeconds
 208     */
 209     @Deprecated
 210     public int getSeconds() {
 211         throw new java.lang.IllegalArgumentException();
 212     }
 213 
 214    /**
 215     * This method is deprecated and should not be used because SQL Date
 216     * values do not have a time component.
 217     *
 218     * @deprecated
 219     * @exception java.lang.IllegalArgumentException if this method is invoked
 220     * @see #getHours
 221     */
 222     @Deprecated
 223     public void setHours(int i) {
 224         throw new java.lang.IllegalArgumentException();
 225     }
 226 
 227    /**
 228     * This method is deprecated and should not be used because SQL Date
 229     * values do not have a time component.
 230     *
 231     * @deprecated
 232     * @exception java.lang.IllegalArgumentException if this method is invoked
 233     * @see #getMinutes
 234     */
 235     @Deprecated
 236     public void setMinutes(int i) {
 237         throw new java.lang.IllegalArgumentException();
 238     }
 239 
 240    /**
 241     * This method is deprecated and should not be used because SQL Date
 242     * values do not have a time component.
 243     *
 244     * @deprecated
 245     * @exception java.lang.IllegalArgumentException if this method is invoked
 246     * @see #getSeconds
 247     */
 248     @Deprecated
 249     public void setSeconds(int i) {
 250         throw new java.lang.IllegalArgumentException();
 251     }
 252 
 253    /**
 254     * Private serial version unique ID to ensure serialization
 255     * compatibility.
 256     */
 257     static final long serialVersionUID = 1511598038487230103L;
 258 }