当前位置: 首页>>代码示例>>Java>>正文


Java Time.getTime方法代码示例

本文整理汇总了Java中java.sql.Time.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java Time.getTime方法的具体用法?Java Time.getTime怎么用?Java Time.getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Time的用法示例。


在下文中一共展示了Time.getTime方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test22

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test22() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime());
    assertFalse(t.before(t2), "Error t.after(t2) = true");
    assertFalse(t2.before(t), "Error t2.after(t) = true");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TimeTests.java

示例2: setTime

import java.sql.Time; //导入方法依赖的package包/类
/**
 * <!-- start generic documentation -->
 * Sets the designated parameter to the given <code>java.sql.Time</code> value,
 * using the given <code>Calendar</code> object.  The driver uses
 * the <code>Calendar</code> object to construct an SQL <code>TIME</code> value,
 * which the driver then sends to the database.  With
 * a <code>Calendar</code> object, the driver can calculate the time
 * taking into account a custom timezone.  If no
 * <code>Calendar</code> object is specified, the driver uses the default
 * timezone, which is that of the virtual machine running the application.
 * <!-- end generic documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information:</h3> <p>
 *
 * When a setXXX method is used to set a parameter of type
 * TIMESTAMP WITH TIME ZONE or TIME WITH TIME ZONE the time zone (including
 * Daylight Saving Time) of the Calendar is used as time zone for the
 * value.<p>
 *
 * </div>
 * <!-- end release-specific documentation -->
 *
 * @param parameterIndex the first parameter is 1, the second is 2, ...
 * @param x the parameter value
 * @param cal the <code>Calendar</code> object the driver will use
 *            to construct the time
 * @exception SQLException if a database access error occurs or
 * this method is called on a closed <code>PreparedStatement</code>
 * @since JDK 1.2 (JDK 1.1.x developers: read the overview for
 *   JDBCParameterMetaData)
 */
public synchronized void setTime(int parameterIndex, Time x,
                                 Calendar cal) throws SQLException {

    checkSetParameterIndex(parameterIndex);

    int i = parameterIndex - 1;

    if (x == null) {
        parameterValues[i] = null;
        parameterSet[i]    = Boolean.TRUE;

        return;
    }

    Type     outType    = parameterTypes[i];
    long     millis     = x.getTime();
    int      zoneOffset = 0;
    Calendar calendar   = cal == null ? session.getCalendar()
            : cal;

    millis = HsqlDateTime.convertMillisFromCalendar(calendar, millis);
    millis = HsqlDateTime.convertToNormalisedTime(millis);

    switch (outType.typeCode) {

        case Types.SQL_TIME :
            break;
        case Types.SQL_TIME_WITH_TIME_ZONE :
            zoneOffset = HsqlDateTime.getZoneMillis(calendar, millis);

            break;
        default :
            throw JDBCUtil.sqlException(ErrorCode.X_42561);
    }
    parameterValues[i] = new TimeData((int) (millis / 1000), 0,
            zoneOffset / 1000);
    parameterSet[i] = Boolean.TRUE;
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:70,代码来源:JDBCPreparedStatement.java

示例3: compare

import java.sql.Time; //导入方法依赖的package包/类
static int compare(Time a, Time b) throws HsqlException {

        if (a.getTime() == b.getTime()) {
            return 0;
        }

        return a.getTime() > b.getTime() ? 1
                                         : -1;
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:10,代码来源:HsqlDateTime.java

示例4: getNormalisedTimestamp

import java.sql.Time; //导入方法依赖的package包/类
public static Timestamp getNormalisedTimestamp(Time t) {

        synchronized (tempCalGMT) {
            setTimeInMillis(tempCalGMT, System.currentTimeMillis());
            resetToDate(tempCalGMT);

            long value = getTimeInMillis(tempCalGMT) + t.getTime();

            return new Timestamp(value);
        }
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:12,代码来源:HsqlDateTime.java

示例5: compare

import java.sql.Time; //导入方法依赖的package包/类
static int compare(Time a, Time b) {

        long atime = a.getTime();
        long btime = b.getTime();

        if (atime == btime) {
            return 0;
        }

        return atime > btime ? 1
                             : -1;
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:13,代码来源:HsqlDateTime.java

示例6: getNormalisedTimestamp

import java.sql.Time; //导入方法依赖的package包/类
public static Timestamp getNormalisedTimestamp(Time t) {

        synchronized (tempCalDefault) {
            setTimeInMillis(tempCalDefault, System.currentTimeMillis());
            resetToDate(tempCalDefault);

            long value = getTimeInMillis(tempCalDefault) + t.getTime();

            return new Timestamp(value);
        }
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:12,代码来源:HsqlDateTime.java

示例7: test15

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test15() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime());
    assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TimeTests.java

示例8: test26

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test26() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime() + 1);
    assertTrue(t.compareTo(t2) == -1, "Error t.compareTo(t2) != -1");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TimeTests.java

示例9: test24

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test24() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime());
    assertTrue(t.compareTo(t2) == 0, "Error t.compareTo(t2) !=0");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TimeTests.java

示例10: testBug5874

import java.sql.Time; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#5874, timezone correction goes in wrong 'direction' (when useTimezone=true and server timezone differs from client timezone).
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug5874() throws Exception {
    TimeZone defaultTimezone = TimeZone.getDefault();

    try {
        String clientTimezoneName = "America/Los_Angeles";
        String serverTimezoneName = "America/Chicago";

        TimeZone.setDefault(TimeZone.getTimeZone(clientTimezoneName));

        long clientTimezoneOffsetMillis = TimeZone.getDefault().getRawOffset();
        long serverTimezoneOffsetMillis = TimeZone.getTimeZone(serverTimezoneName).getRawOffset();

        long offsetDifference = clientTimezoneOffsetMillis - serverTimezoneOffsetMillis;

        SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

        long pointInTime = timestampFormat.parse("2004-10-04 09:19:00").getTime();

        Properties props = new Properties();
        props.put("useTimezone", "true");
        props.put("serverTimezone", serverTimezoneName);
        props.put("cacheDefaultTimezone", "false");

        Connection tzConn = getConnectionWithProps(props);
        Statement tzStmt = tzConn.createStatement();
        createTable("testBug5874", "(tstamp DATETIME, t TIME)");

        PreparedStatement tsPstmt = tzConn.prepareStatement("INSERT INTO testBug5874 VALUES (?, ?)");

        tsPstmt.setTimestamp(1, new Timestamp(pointInTime));
        tsPstmt.setTime(2, new Time(pointInTime));
        tsPstmt.executeUpdate();

        this.rs = tzStmt.executeQuery("SELECT * from testBug5874");

        while (this.rs.next()) { // Driver now converts/checks DATE/TIME/TIMESTAMP/DATETIME types when calling getString()...
            String retrTimestampString = new String(this.rs.getBytes(1));
            Timestamp retrTimestamp = this.rs.getTimestamp(1);

            java.util.Date timestampOnServer = timestampFormat.parse(retrTimestampString);

            long retrievedOffsetForTimestamp = retrTimestamp.getTime() - timestampOnServer.getTime();

            assertEquals("Original timestamp and timestamp retrieved using client timezone are not the same", offsetDifference,
                    retrievedOffsetForTimestamp);

            String retrTimeString = new String(this.rs.getBytes(2));
            Time retrTime = this.rs.getTime(2);

            java.util.Date timeOnServerAsDate = timeFormat.parse(retrTimeString);
            Time timeOnServer = new Time(timeOnServerAsDate.getTime());

            long retrievedOffsetForTime = retrTime.getTime() - timeOnServer.getTime();

            assertEquals("Original time and time retrieved using client timezone are not the same", offsetDifference, retrievedOffsetForTime);
        }

        tzConn.close();
    } finally {
        TimeZone.setDefault(defaultTimezone);
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:70,代码来源:StatementRegressionTest.java

示例11: convertStringTypes

import java.sql.Time; //导入方法依赖的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;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:67,代码来源:SqoopHCatExportHelper.java

示例12: getLong

import java.sql.Time; //导入方法依赖的package包/类
@Override public long getLong() throws SQLException {
  Time time = getTime(null);
  return time == null ? 0L
      : (time.getTime() % DateTimeUtils.MILLIS_PER_DAY);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:6,代码来源:AbstractCursor.java

示例13: test25

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test25() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime() + 1);
    assertTrue(t2.compareTo(t) == 1, "Error t2.compareTo(t) !=1");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TimeTests.java


注:本文中的java.sql.Time.getTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。