java.sql

Class Date

Implemented Interfaces:
Cloneable, Comparable<T>, Serializable

public class Date
extends Date

A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. 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.

See Also:
Serialized Form

Constructor Summary

Date(long date)
Constructs a Date object using the given milliseconds time value.

Method Summary

@Deprecated
int getHours()
Deprecated.
@Deprecated
int getMinutes()
Deprecated.
@Deprecated
int getSeconds()
Deprecated.
void
setTime(long date)
Sets an existing Date object using the given milliseconds time value.
String
toString()
Formats a date in the date escape format yyyy-mm-dd.
static Date
valueOf(String s)
Converts a string in JDBC date escape format to a Date value.
@Deprecated
void setHours(int i)
Deprecated.
@Deprecated
void setMinutes(int i)
Deprecated.
@Deprecated
void setSeconds(int i)
Deprecated.

Methods inherited from class java.util.Date

String toGMTString, String toLocaleString, after, before, clone, compareTo, equals, getTime, hashCode, int getDate, int getDay, int getHours, int getMinutes, int getMonth, int getSeconds, int getTimezoneOffset, int getYear, long UTC, long parse, setTime, toString, void setDate, void setHours, void setMinutes, void setMonth, void setSeconds, void setYear

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Date

public Date(long date)
Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.
Parameters:
date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.
Usages and Demos :

View More Examples of Date(long date)
   1:         
   2:         st.setDate( index,  new Date( ( (Calendar) value ).getTime().getTime() ) );
   3:     }
   4:     
   5:     public int sqlType() {

View Full Code Here
   1:         {
   2:             return new Date(((Calendar) source).getTime().getTime());
   3:         }
   4:         else
   5:         {

View Full Code Here
   1:             
   2:         st.setDate( index,  new Date( ( (Calendar) value ).getTime().getTime() ) );
   3:     }
   4: 
   5:     public int sqlType() {

View Full Code Here
   1:         } else if (object instanceof Calendar) {
   2:             printString("new java.util.Date(");
   3:             printString(String.valueOf(((Calendar)object).getTimeInMillis()));
   4:         ...
   5:         } else if (object.getClass() == ClassConstants.SQLDATE) {
   6:             printString("new java.sql.Date(");
   7:             printString(String.valueOf(((java.sql.Date)object).getTime()));
   8:         ...
   9:         } else if (object.getClass() == ClassConstants.UTILDATE) {
  10:             printString("new java.util.Date(");
  11:             printString(String.valueOf(((java.util.Date)object).getTime()));

View Full Code Here
   1:         } else if(value instanceof Number) {
   2:             return new Date(((Number)value).longValue());
   3:         } else {
   4:         }
   5:     }

View Full Code Here

Method Details

int getHours

public @Deprecated int getHours()

Deprecated.

This method is deprecated and should not be used because SQL Date values do not have a time component.
Overrides:
int getHours in interface Date
Throws:
IllegalArgumentException - if this method is invoked
See Also:
Date

int getMinutes

public @Deprecated int getMinutes()

Deprecated.

This method is deprecated and should not be used because SQL Date values do not have a time component.
Overrides:
int getMinutes in interface Date
Throws:
IllegalArgumentException - if this method is invoked
See Also:
Date

int getSeconds

public @Deprecated int getSeconds()

Deprecated.

This method is deprecated and should not be used because SQL Date values do not have a time component.
Overrides:
int getSeconds in interface Date
Throws:
IllegalArgumentException - if this method is invoked
See Also:
Date

setTime

public void setTime(long date)
Sets an existing Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.
Overrides:
setTime in interface Date
Parameters:
date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.
Usages and Demos :

View More Examples of setTime(long date)
   1: 
   2: import java.sql.Date;
   3: 
   4:         ...
   5: 
   6:     private static final String _xmlName = "sql-date";
   7: 
   8:         ...
   9:                     {
  10:                         if (java.sql.Date.class == object.getClass()) {
  11:                             Date target = (Date)object;
  12:         ...
  13:                             if (java.util.Date.class.isAssignableFrom(value.getClass())) {
  14:                                 target.setTime(((Date)value).getTime());

View Full Code Here
   1: 
   2:   public static java.sql.Date parseDateString(String tmp) {
   3:         ...
   4:     java.sql.Date dateValue = null;
   5:     try {
   6:         ...
   7:       java.util.Date tmpDate = DateFormat.getDateInstance(DateFormat.SHORT).parse(tmp);
   8:       dateValue = new java.sql.Date(new java.util.Date().getTime());
   9:         ...
  10:       dateValue.setTime(tmpDate.getTime());

View Full Code Here
   1: 
   2:   public static String castDateTimeToDate(Connection db, String date) {
   3:     switch (DatabaseUtils.getType(db)) {
   4:         ...
   5:       case DatabaseUtils.POSTGRESQL:
   6:         return (date + "::date");
   7:       case DatabaseUtils.MSSQL:
   8:         ...
   9:         return ("CONVERT(char(10), " + date + ", 101)");
  10:       case DatabaseUtils.FIREBIRD:
  11:         ...
  12:       dateValue = new java.sql.Date(new java.util.Date().getTime());
  13:       dateValue.setTime(tmpDate.getTime());

View Full Code Here

toString

public String toString()
Formats a date in the date escape format yyyy-mm-dd.

NOTE: To specify a date format for the class SimpleDateFormat, use "yyyy.MM.dd" rather than "yyyy-mm-dd". In the context of SimpleDateFormat, "mm" indicates minutes rather than the month. For example:


  Format Pattern                         Result
  --------------                         -------
	"yyyy.MM.dd G 'at' hh:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT
 
Overrides:
toString in interface Date
Returns:
a String in yyyy-mm-dd format
Usages and Demos :

View More Examples of toString()
   1: import javax.servlet.http.HttpServletRequest;
   2: import java.sql.Date;
   3: import java.util.Calendar;
   4:         ...
   5: 
   6:     private Date d;
   7:     private String rep;
   8:         ...
   9: 
  10:     public DateFormat(Date d)
  11:     {
  12:         ...
  13:         else
  14:             rep = d.toString();

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.sql.Date;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     public void setUserCredential(String name, char[] password, Date expirationDate, boolean isEnabled, boolean isExpired, boolean requireUpdate)
   7:     {
   8:         ...
   9:             {
  10:                 pwData.getMyMap().put("expirationDate",expirationDate.toString());
  11:             }
  12:         ...
  13:     
  14:     public Date getPwExpirationDate()

View Full Code Here
   1: 
   2: import java.sql.Date;
   3: import java.sql.Time;
   4:         ...
   5: 
   6:     public static final Date getPGDate(String val) throws SQLException {
   7:         if (null == val) {
   8:         ...
   9:                 Timestamp ts = PGDateTimeTypes.textToTimestamp(val);
  10:                 return Date.valueOf(ts.toString().substring(0, 10));
  11:             } else {
  12:         ...
  13:                 return Date.valueOf(val);

View Full Code Here
   1:         } catch(SQLException e) {
   2:             trace(e.toString());
   3:         }
   4:         ...
   5:         } catch(SQLException e) {
   6:             trace(e.toString());
   7:         }
   8:         ...
   9:         check(o instanceof String);
  10:         check(o.toString().equals("Hi"));
  11:         
  12:         ...
  13:         stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE DATETIME)");
  14:         stat.execute("INSERT INTO TEST VALUES(1,DATE '2011-11-11')");

View Full Code Here

valueOf

public static Date valueOf(String s)
Converts a string in JDBC date escape format to a Date value.
Parameters:
s - a String object representing a date in in the format "yyyy-mm-dd"
Returns:
a java.sql.Date object representing the given date
Throws:
IllegalArgumentException - if the date given is not in the JDBC date escape format (yyyy-mm-dd)
Usages and Demos :

View More Examples of valueOf(String s)
   1: 
   2: import java.sql.Date;
   3: 
   4:         ...
   5:       dateDef = 
   6:         new PropDefDate (defId, "dateTest", "none", "test property date");
   7:     } catch (InvalidPropDefException e) {
   8:         ...
   9:       fail("Could not create property definition for Date : " + 
  10:            e.getMessage());   
  11:         ...
  12:         
  13:     String[] thirdValueIsBad = {Date.valueOf("1999-07-08").toString(),

View Full Code Here

void setHours

public @Deprecated void setHours(int i)

Deprecated.

This method is deprecated and should not be used because SQL Date values do not have a time component.
Overrides:
void setHours in interface Date
Throws:
IllegalArgumentException - if this method is invoked
See Also:
Date

void setMinutes

public @Deprecated void setMinutes(int i)

Deprecated.

This method is deprecated and should not be used because SQL Date values do not have a time component.
Overrides:
void setMinutes in interface Date
Throws:
IllegalArgumentException - if this method is invoked
See Also:
Date

void setSeconds

public @Deprecated void setSeconds(int i)

Deprecated.

This method is deprecated and should not be used because SQL Date values do not have a time component.
Overrides:
void setSeconds in interface Date
Throws:
IllegalArgumentException - if this method is invoked
See Also:
Date