當前位置: 首頁>>代碼示例>>Java>>正文


Java Date類代碼示例

本文整理匯總了Java中java.sql.Date的典型用法代碼示例。如果您正苦於以下問題:Java Date類的具體用法?Java Date怎麽用?Java Date使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Date類屬於java.sql包,在下文中一共展示了Date類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBug54095

import java.sql.Date; //導入依賴的package包/類
/**
 * Tests fix for BUG#54095 - Unnecessary call in newSetTimestampInternal.
 *
 * This bug was fixed as a consequence of the patch for Bug#71084.
 *
 * @throws Exception
 *             if the test fails.
 */
public void testBug54095() throws Exception {
    Connection testConn = getConnectionWithProps("useLegacyDatetimeCode=false");

    Calendar testCal = Calendar.getInstance();
    java.util.Date origDate = testCal.getTime();

    PreparedStatement testPstmt = testConn.prepareStatement("SELECT ?");
    testPstmt.setTimestamp(1, new Timestamp(0), testCal);
    assertEquals("Calendar object shouldn't have changed after PreparedStatement.setTimestamp().", origDate, testCal.getTime());

    ResultSet testRs = testPstmt.executeQuery();
    testRs.next();
    assertEquals("Calendar object shouldn't have changed after PreparedStatement.executeQuery().", origDate, testCal.getTime());

    testRs.getTimestamp(1, testCal);
    assertEquals("Calendar object shouldn't have changed after ResultSet.getTimestamp().", origDate, testCal.getTime());

    testRs.close();
    testPstmt.close();
    testConn.close();
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:30,代碼來源:StatementRegressionTest.java

示例2: PreparedStmtSetValue

import java.sql.Date; //導入依賴的package包/類
private  void PreparedStmtSetValue(CallableStatement cStmt, int idx, Object obj) throws SQLException{
	if (obj instanceof String) {
		pStmt.setString(idx, (String) obj);
	} else if(obj instanceof Integer){
		pStmt.setInt(idx, (Integer) obj);
	} else if(obj instanceof BigDecimal){
			pStmt.setBigDecimal(idx, (BigDecimal) obj);
	} else if(obj instanceof Double){
		pStmt.setDouble(idx, (Double) obj);
	} else if(obj instanceof Date){
		pStmt.setDate(idx, (Date) obj);
	} else if(obj instanceof byte[]){
		pStmt.setBytes(idx, (byte[]) obj);			
	} else{
		pStmt.setObject(idx, obj);
	}
}
 
開發者ID:experdb,項目名稱:eXperDB-DB2PG,代碼行數:18,代碼來源:DataAdapter.java

示例3: testDateTypesToBigInt

import java.sql.Date; //導入依賴的package包/類
public void testDateTypesToBigInt() throws Exception {
  final int TOTAL_RECORDS = 1 * 10;
  long offset = TimeZone.getDefault().getRawOffset();
  String table = getTableName().toUpperCase();
  ColumnGenerator[] cols = new ColumnGenerator[] {
    HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0),
      "date", Types.DATE, HCatFieldSchema.Type.BIGINT, 0, 0, 0 - offset,
      new Date(70, 0, 1), KeyType.NOT_A_KEY),
    HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1),
      "time", Types.TIME, HCatFieldSchema.Type.BIGINT, 0, 0,
      36672000L - offset, new Time(10, 11, 12), KeyType.NOT_A_KEY),
    HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2),
      "timestamp", Types.TIMESTAMP, HCatFieldSchema.Type.BIGINT, 0, 0,
      36672000L - offset, new Timestamp(70, 0, 1, 10, 11, 12, 0),
      KeyType.NOT_A_KEY),
  };
  List<String> addlArgsArray = new ArrayList<String>();
  addlArgsArray.add("--map-column-hive");
  addlArgsArray.add("COL0=bigint,COL1=bigint,COL2=bigint");
  runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols);
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:22,代碼來源:HCatalogExportTest.java

示例4: testLogin

import java.sql.Date; //導入依賴的package包/類
@Test
public void testLogin()
{  
    Pet Pet = new Pet(11, 9527, "肥仔", 1, 60, 40, new Date(2017-1-1), "寶貝");

    Scanner sc = new Scanner(System.in);
    System.out.println("請輸入登陸名:");
    String username = sc.next();
    System.out.println("請輸入密碼:");
    String password = sc.next();
    Master master = new Master(username, password);

    Connection conn = DBHelper.getInstance().getConnection();
    MasterDao dao = new MasterServiceImpl(conn);
    MasterService service = new MasterServiceImpl(dao);

    service.login(master);

    DBHelper.closeConnection(conn);    
}
 
開發者ID:JAVA201708,項目名稱:Homework,代碼行數:21,代碼來源:DAOEx03.java

示例5: testGetTaskCountByWorkbasketAndDaysInPastAndState

import java.sql.Date; //導入依賴的package包/類
@Test
public void testGetTaskCountByWorkbasketAndDaysInPastAndState() {
    final long daysInPast = 10L;
    List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
    List<DueWorkbasketCounter> expectedResult = new ArrayList<>();
    doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(
        any(Date.class),
        any());

    List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,
        taskStates);

    verify(taskanaEngineImpl, times(1)).openConnection();
    verify(taskMonitorMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
    verify(taskanaEngineImpl, times(1)).returnConnection();
    verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
        taskMonitorMapperMock, objectReferenceMapperMock, workbasketServiceMock);
    assertThat(actualResult, equalTo(expectedResult));
}
 
開發者ID:Taskana,項目名稱:taskana,代碼行數:20,代碼來源:TaskMonitorServiceImplTest.java

示例6: generateTestDataFileForPartitionInput

import java.sql.Date; //導入依賴的package包/類
private String generateTestDataFileForPartitionInput() throws Exception {
  final File file = getTempFile();

  PrintWriter printWriter = new PrintWriter(file);

  String partValues[] = {"1", "2", "null"};

  for(int c = 0; c < partValues.length; c++) {
    for(int d = 0; d < partValues.length; d++) {
      for(int e = 0; e < partValues.length; e++) {
        for (int i = 1; i <= 5; i++) {
          Date date = new Date(System.currentTimeMillis());
          Timestamp ts = new Timestamp(System.currentTimeMillis());
          printWriter.printf("%s,%s,%s,%s,%s",
              date.toString(), ts.toString(), partValues[c], partValues[d], partValues[e]);
          printWriter.println();
        }
      }
    }
  }

  printWriter.close();

  return file.getPath();
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:26,代碼來源:HiveTestDataGenerator.java

示例7: date2Obj

import java.sql.Date; //導入依賴的package包/類
private static Object date2Obj(Object value, String type, String format) {
	String fromType = "Date";
	java.util.Date dte = (java.util.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(dte);
		}
	} else if ("Date".equalsIgnoreCase(type) || DataType.DATE.equalsIgnoreCase(type)) {
		return value;
	} else if ("java.sql.Date".equalsIgnoreCase(type)) {
		return new Date(dte.getTime());
	} else if ("Time".equalsIgnoreCase(type) || DataType.TIME.equalsIgnoreCase(type)) {
		return new Time(dte.getTime());
	} else if ("Timestamp".equalsIgnoreCase(type) || DataType.TIMESTAMP.equalsIgnoreCase(type)) {
		return new Timestamp(dte.getTime());
	} else {
		throw new DataParseException(String.format(support, fromType, type));
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:23,代碼來源:TypeParseUtil.java

示例8: testCrearPassword

import java.sql.Date; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void testCrearPassword() {
	List<Ciudadano> ciudadanos = new ArrayList<Ciudadano>();

	Ciudadano ciudadano = new Ciudadano("Hugo", "Perez", "[email protected]", "Calle no se que Oviedo", "español", "1234A",
			new Date(18, 7, 1995));

	ciudadanos.add(ciudadano);
	BBDD.insertarCiudadano(ciudadanos);
	Ciudadano cBBDD = BBDD.obtenerCiudadano("1234A");
	cBBDD.crearPassword();
	String password = cBBDD.getPassword();
	BBDD.guardaarPasswordUsuario("1234A", password);
	cBBDD = BBDD.obtenerCiudadano("1234A");

	assertEquals(password, cBBDD.getPassword());
}
 
開發者ID:Arquisoft,項目名稱:citizensLoader2b,代碼行數:19,代碼來源:AplicationTest.java

示例9: setParam

import java.sql.Date; //導入依賴的package包/類
public void setParam(PreparedStatement ps, int parameterIndex,
                     Object object) throws SQLException {
    if (object instanceof Timestamp) {
        ps.setTimestamp(parameterIndex, (Timestamp) object);
    } else if (object instanceof Date) {
        ps.setDate(parameterIndex, (Date) object);
    } else if (object instanceof String) {
        ps.setString(parameterIndex, (String) object);
    } else if (object instanceof Integer) {
        ps.setInt(parameterIndex, ((Integer) object).intValue());
    } else if (object instanceof Long) {
        ps.setLong(parameterIndex, ((Long) object).longValue());
    } else if (object instanceof Boolean) {
        ps.setBoolean(parameterIndex, ((Boolean) object).booleanValue());
    } else {
        ps.setObject(parameterIndex, object);
    }
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:19,代碼來源:JDBCTemplate.java

示例10: setDate

import java.sql.Date; //導入依賴的package包/類
public void setDate(String parameterName, Date x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDate(parameterName, x);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:12,代碼來源:CallableStatementWrapper.java

示例11: getNormalisedTimestamp

import java.sql.Date; //導入依賴的package包/類
public static Timestamp getNormalisedTimestamp(Date d) {

        synchronized (tempCalDefault) {
            setTimeInMillis(tempCalDefault, d.getTime());
            resetToDate(tempCalDefault);

            long value = getTimeInMillis(tempCalDefault);

            return new Timestamp(value);
        }
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:12,代碼來源:HsqlDateTime.java

示例12: appendLog

import java.sql.Date; //導入依賴的package包/類
@Override
public void appendLog(StringBuilder builder, Date parameter, DatabaseDialect dialect) {
	// if (DatabaseDialect.MYSQL == dialect) {
	// builder.append('\'');
	// builder.append((null != parameter) ? new SimpleDateFormat("yyyy-MM-dd").format(parameter) : null);
	// builder.append('\'');
	// }
	builder.append('\'');
	builder.append((null != parameter) ? new SimpleDateFormat("yyyy-MM-dd").format(parameter) : null);
	builder.append('\'');
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:12,代碼來源:SqlDateTypeHandler.java

示例13: setDate

import java.sql.Date; //導入依賴的package包/類
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDate(parameterName, x, cal);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:12,代碼來源:CallableStatementWrapper.java

示例14: testGetPredicateForDate

import java.sql.Date; //導入依賴的package包/類
/**
 * Test for Date values.
 *
 * @param constant the constant value to be tested
 * @param op the operation to be used for testing/condition against constant value
 * @param arg1 the value to be compared against the constant value
 * @param check boolean indicating the result of predicate test for above
 */
@Test(dataProvider = "getDateData")
public void testGetPredicateForDate(final Object constant, final TypePredicateOp op,
    final Date arg1, boolean check) {
  System.out.printf("PredicateHelperTest.testGetPredicateForDate :: %s -- %s -- %s -- %s\n",
      constant, op, arg1, check);

  assertUsingSerDeForType(BasicTypes.DATE, constant, op, arg1, check);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:17,代碼來源:MPredicateHelperTest.java

示例15: getNormalisedDate

import java.sql.Date; //導入依賴的package包/類
public static Date getNormalisedDate(Date d) {

        synchronized (tempCalDefault) {
            setTimeInMillis(tempCalDefault, d.getTime());
            resetToDate(tempCalDefault);

            long value = getTimeInMillis(tempCalDefault);

            return new Date(value);
        }
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:12,代碼來源:HsqlDateTime.java


注:本文中的java.sql.Date類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。