本文整理汇总了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");
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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");
}
示例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");
}
示例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");
}
示例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);
}
}
示例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;
}
示例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);
}
示例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");
}