本文整理汇总了Java中java.sql.Date.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java Date.getTime方法的具体用法?Java Date.getTime怎么用?Java Date.getTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Date
的用法示例。
在下文中一共展示了Date.getTime方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sqlDate2Obj
import java.sql.Date; //导入方法依赖的package包/类
private static Object sqlDate2Obj(Object value, String type, String format) {
String fromType = "Date";
Date dte = (Date) value;
if ("String".equalsIgnoreCase(type) || DataType.STRING.equalsIgnoreCase(type)) {
if (format == null || format.length() == 0) {
return dte.toString();
} else {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new java.util.Date(dte.getTime()));
}
} else if ("Date".equalsIgnoreCase(type) || DataType.DATE.equalsIgnoreCase(type)) {
return new java.util.Date(dte.getTime());
} else if ("java.sql.Date".equalsIgnoreCase(type)) {
return value;
} else if ("Time".equalsIgnoreCase(type) || DataType.TIME.equalsIgnoreCase(type)) {
throw new DataParseException("Conversion from " + fromType + " to " + type + " not currently supported");
} else if ("Timestamp".equalsIgnoreCase(type) || DataType.TIMESTAMP.equalsIgnoreCase(type)) {
return new Timestamp(dte.getTime());
} else {
throw new DataParseException(String.format(support, fromType, type));
}
}
示例2: addToCache
import java.sql.Date; //导入方法依赖的package包/类
private synchronized void addToCache(String searchCriteria, List list)
{
Date now = new Date(System.currentTimeMillis());
List cacheEntry = new ArrayList();
cacheEntry.add(now);
cacheEntry.add(list);
if (cacheMap.containsKey(searchCriteria))
{
cacheMap.put(searchCriteria, cacheEntry);
}
else
{
if (cacheMap.size() >= cacheSize)
{
// replace oldest
Iterator it = cacheMap.entrySet().iterator();
long oldest = now.getTime();
Object replace = null;
while (it.hasNext())
{
Map.Entry entry = (Map.Entry)it.next();
long current = ((Date)((List)entry.getValue()).get(0))
.getTime();
if (current < oldest)
{
oldest = current;
replace = entry.getKey();
}
}
cacheMap.remove(replace);
}
cacheMap.put(searchCriteria, cacheEntry);
}
}
示例3: test19
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test19() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertTrue(d.equals(d2), "Error d != d2");
}
示例4: compare
import java.sql.Date; //导入方法依赖的package包/类
static int compare(Date a, Date b) {
long atime = a.getTime();
long btime = b.getTime();
if (atime == btime) {
return 0;
}
return atime > btime ? 1
: -1;
}
示例5: test8
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test8() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d.before(d2), "Error d.before(d2) = true");
assertFalse(d2.before(d), "Error d2.before(d) = true");
}
示例6: test4
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test4() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d.after(d2), "Error d.after(d2) = true");
assertFalse(d2.after(d), "Error d2.after(d) = true");
}
示例7: test7
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test7() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d2.before(d), "Error d2.before(d) = true");
}
示例8: SpecificTimestampProvider
import java.sql.Date; //导入方法依赖的package包/类
public SpecificTimestampProvider ( Date date )
{
this.ts = date.getTime ();
}
示例9: convertStringTypes
import java.sql.Date; //导入方法依赖的package包/类
private Object convertStringTypes(Object val, String javaColType) {
String valStr = val.toString();
if (javaColType.equals(BIG_DECIMAL_TYPE)) {
return new BigDecimal(valStr);
} else if (javaColType.equals(DATE_TYPE)
|| javaColType.equals(TIME_TYPE)
|| javaColType.equals(TIMESTAMP_TYPE)) {
// Oracle expects timestamps for Date also by default based on version
// Just allow all date types to be assignment compatible
if (valStr.length() == 10
&& valStr.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
// Date in yyyy-mm-dd format
Date d = Date.valueOf(valStr);
if (javaColType.equals(DATE_TYPE)) {
return d;
} else if (javaColType.equals(TIME_TYPE)) {
return new Time(d.getTime());
} else if (javaColType.equals(TIMESTAMP_TYPE)) {
return new Timestamp(d.getTime());
}
} else if (valStr.length() == 8
&& valStr.matches("^\\d{2}:\\d{2}:\\d{2}$")) {
// time in hh:mm:ss
Time t = Time.valueOf(valStr);
if (javaColType.equals(DATE_TYPE)) {
return new Date(t.getTime());
} else if (javaColType.equals(TIME_TYPE)) {
return t;
} else if (javaColType.equals(TIMESTAMP_TYPE)) {
return new Timestamp(t.getTime());
}
} else if (valStr.length() >= 19
&& valStr.length() <= 26
&& valStr.
matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.\\d+)?$")) {
// timestamp in yyyy-mm-dd hh:mm:ss
Timestamp ts = Timestamp.valueOf(valStr);
if (javaColType.equals(DATE_TYPE)) {
return new Date(ts.getTime());
} else if (javaColType.equals(TIME_TYPE)) {
return new Time(ts.getTime());
} else if (javaColType.equals(TIMESTAMP_TYPE)) {
return ts;
}
} else {
return null;
}
} else if (javaColType.equals(STRING_TYPE)) {
return valStr;
} else if (javaColType.equals(BOOLEAN_TYPE)) {
return Boolean.valueOf(valStr);
} else if (javaColType.equals(BYTE_TYPE)) {
return Byte.parseByte(valStr);
} else if (javaColType.equals(SHORT_TYPE)) {
return Short.parseShort(valStr);
} else if (javaColType.equals(INTEGER_TYPE)) {
return Integer.parseInt(valStr);
} else if (javaColType.equals(LONG_TYPE)) {
return Long.parseLong(valStr);
} else if (javaColType.equals(FLOAT_TYPE)) {
return Float.parseFloat(valStr);
} else if (javaColType.equals(DOUBLE_TYPE)) {
return Double.parseDouble(valStr);
}
return null;
}
示例10: checkPrepareBindExecuteFetchDate
import java.sql.Date; //导入方法依赖的package包/类
private void checkPrepareBindExecuteFetchDate(Connection connection) throws Exception {
final String sql0 =
"select cast(? as varchar(20)) as c\n"
+ "from (values (1, 'a'))";
final String sql1 = "select ? + interval '2' day as c from (values (1, 'a'))";
final Date date = Date.valueOf("2015-04-08");
final long time = date.getTime();
PreparedStatement ps;
ParameterMetaData parameterMetaData;
ResultSet resultSet;
ps = connection.prepareStatement(sql0);
parameterMetaData = ps.getParameterMetaData();
assertThat(parameterMetaData.getParameterCount(), equalTo(1));
ps.setDate(1, date);
resultSet = ps.executeQuery();
assertThat(resultSet.next(), is(true));
assertThat(resultSet.getString(1), is("2015-04-08"));
ps.setTimestamp(1, new Timestamp(time));
resultSet = ps.executeQuery();
assertThat(resultSet.next(), is(true));
assertThat(resultSet.getString(1), is("2015-04-08 00:00:00.0"));
ps.setTime(1, new Time(time));
resultSet = ps.executeQuery();
assertThat(resultSet.next(), is(true));
assertThat(resultSet.getString(1), is("00:00:00"));
ps.close();
ps = connection.prepareStatement(sql1);
parameterMetaData = ps.getParameterMetaData();
assertThat(parameterMetaData.getParameterCount(), equalTo(1));
ps.setDate(1, date);
resultSet = ps.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getDate(1),
equalTo(new Date(time + TimeUnit.DAYS.toMillis(2))));
assertThat(resultSet.getTimestamp(1),
equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));
ps.setTimestamp(1, new Timestamp(time));
resultSet = ps.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getTimestamp(1),
equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));
assertThat(resultSet.getTimestamp(1),
equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));
ps.setObject(1, new java.util.Date(time));
resultSet = ps.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getDate(1),
equalTo(new Date(time + TimeUnit.DAYS.toMillis(2))));
assertThat(resultSet.getTimestamp(1),
equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));
resultSet.close();
ps.close();
connection.close();
}
示例11: getValue
import java.sql.Date; //导入方法依赖的package包/类
private static Object getValue(ResultSet resultSet, int type, int j,
Calendar calendar) throws SQLException {
switch (type) {
case Types.BIGINT:
final long aLong = resultSet.getLong(j + 1);
return aLong == 0 && resultSet.wasNull() ? null : aLong;
case Types.INTEGER:
final int anInt = resultSet.getInt(j + 1);
return anInt == 0 && resultSet.wasNull() ? null : anInt;
case Types.SMALLINT:
final short aShort = resultSet.getShort(j + 1);
return aShort == 0 && resultSet.wasNull() ? null : aShort;
case Types.TINYINT:
final byte aByte = resultSet.getByte(j + 1);
return aByte == 0 && resultSet.wasNull() ? null : aByte;
case Types.DOUBLE:
case Types.FLOAT:
final double aDouble = resultSet.getDouble(j + 1);
return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
case Types.REAL:
final float aFloat = resultSet.getFloat(j + 1);
return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
case Types.DATE:
final Date aDate = resultSet.getDate(j + 1, calendar);
return aDate == null
? null
: (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
case Types.TIME:
final Time aTime = resultSet.getTime(j + 1, calendar);
return aTime == null
? null
: (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
case Types.TIMESTAMP:
final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
return aTimestamp == null ? null : aTimestamp.getTime();
case Types.ARRAY:
final Array array = resultSet.getArray(j + 1);
if (null == array) {
return null;
}
try {
// Recursively extracts an Array using its ResultSet-representation
return extractUsingResultSet(array, calendar);
} catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
// Not every database might implement Array.getResultSet(). This call
// assumes a non-nested array (depends on the db if that's a valid assumption)
return extractUsingArray(array, calendar);
}
case Types.STRUCT:
Struct struct = resultSet.getObject(j + 1, Struct.class);
Object[] attrs = struct.getAttributes();
List<Object> list = new ArrayList<>(attrs.length);
for (Object o : attrs) {
list.add(o);
}
return list;
default:
return resultSet.getObject(j + 1);
}
}
示例12: getLong
import java.sql.Date; //导入方法依赖的package包/类
@Override public long getLong() throws SQLException {
Date date = getDate(null);
return date == null
? 0L
: (date.getTime() / DateTimeUtils.MILLIS_PER_DAY);
}
示例13: test10
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test10() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
}
示例14: test3
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test3() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d.after(d2), "Error d.after(d2) = true");
}