本文整理汇总了Java中java.sql.Timestamp.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java Timestamp.getTime方法的具体用法?Java Timestamp.getTime怎么用?Java Timestamp.getTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Timestamp
的用法示例。
在下文中一共展示了Timestamp.getTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import java.sql.Timestamp; //导入方法依赖的package包/类
/**
* 过滤掉LOG日志比当前时间小较多的数据, 避免长时间处理旧数据
*
* @param entry
* @param iEntryFilterChain
*
* @throws WispProcessorException
*/
@Override
public void doFilter(MysqlEntryWrap entry, IEntryFilterChain iEntryFilterChain) throws WispProcessorException {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
long currentTime = timestamp.getTime();
long logTime = entry.getMysqlEntry().getTime();
// 5s
if (logTime + 1000 * 5 < currentTime) {
LOGGER.warn("ignore entry because of smaller time logTime:{}, currentTime:{}, entry{} ", logTime,
currentTime, entry);
} else {
iEntryFilterChain.doFilter(entry);
}
}
示例2: getNullableResult
import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public Date getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
Timestamp sqlTimestamp = cs.getTimestamp(columnIndex);
if (sqlTimestamp != null) {
return new Date(sqlTimestamp.getTime());
}
return null;
}
示例3: getDate
import java.sql.Timestamp; //导入方法依赖的package包/类
@Override public Date getDate(Calendar calendar) throws SQLException {
final Timestamp timestamp = getTimestamp(calendar);
if (timestamp == null) {
return null;
}
return new Date(timestamp.getTime());
}
示例4: getDate
import java.sql.Timestamp; //导入方法依赖的package包/类
public Date getDate(int columnIndex) throws ParseException {
try {
Timestamp e = DatabaseDataSet.this.resultSet.getTimestamp(this.getDatabaseColumnIndex(columnIndex));
return DatabaseDataSet.this.resultSet.wasNull()?null:new Date(e.getTime());
} catch (SQLException var3) {
throw new ParseException(var3.getMessage(), var3);
}
}
示例5: map
import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public DBUser map(int index, ResultSet r, StatementContext ctx) throws SQLException {
Timestamp stamp = r.getTimestamp("cooldown_expiry");
Timestamp ban = r.getTimestamp("ban_expiry");
return new DBUser(
r.getInt("id"),
r.getString("username"),
r.getString("login"),
stamp == null ? 0 : stamp.getTime(),
Role.valueOf(r.getString("role")),
ban == null ? 0 : ban.getTime()
);
}
示例6: getImageDate
import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public Date getImageDate(){
String ts=getTimeStampStart();
ts=ts.replace("Z", "");
Timestamp t=Timestamp.valueOf(ts);
return new Date(t.getTime());
}
示例7: testOk
import java.sql.Timestamp; //导入方法依赖的package包/类
@Test
public void testOk() {
// Given logger
LogbackCapturingAppender capturing = LogbackCapturingAppender.Factory.weaveInto(EntryTimeFilter.getLOGGER());
IEntryFilter entryFilter = new EntryTimeFilter();
List<IEntryFilter> filters = new ArrayList<>();
filters.add(entryFilter);
filters.add(entryFilter);
IEntryFilterChain entryFilterChain = EntryFilterChainFactory.getEntryFilterChain(filters);
try {
MysqlEntry mysqlEntry = new MysqlEntry();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
long currentTime = timestamp.getTime();
mysqlEntry.setTime(currentTime - 1000 * 2);
entryFilterChain.doFilter(new MysqlEntryWrap("topic", mysqlEntry));
} catch (WispProcessorException e) {
Assert.assertTrue(false);
}
Assert.assertEquals(capturing.getCapturedLogMessage(), null);
}
示例8: getDifference
import java.sql.Timestamp; //导入方法依赖的package包/类
private String getDifference(Timestamp begin, Timestamp end)
{
long diff = end.getTime() - begin.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);
return diffDays + " days, " + diffHours + " hours, " + diffMinutes + " minutes, " + diffSeconds + " seconds";
}
示例9: compareTimestamps
import java.sql.Timestamp; //导入方法依赖的package包/类
/**
* Compares two Timestamps with the expected result.
*
* @param ts1 the first Timestamp
* @param ts2 the second Timestamp
* @param expect the expected relation between ts1 and ts2; 0 if
* ts1 equals to ts2, or 1 if ts1 is after ts2, or -1 if ts1 is
* before ts2.
*/
private void compareTimestamps(Timestamp ts1, Timestamp ts2, int expected) {
boolean expectedResult = expected > 0;
boolean result = ts1.after(ts2);
if (result != expectedResult) {
errln("ts1.after(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
expectedResult = expected < 0;
result = ts1.before(ts2);
if (result != expectedResult) {
errln("ts1.before(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
expectedResult = expected == 0;
result = ts1.equals(ts2);
if (result != expectedResult) {
errln("ts1.equals(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
int x = ts1.compareTo(ts2);
int y = (x > 0) ? 1 : (x < 0) ? -1 : 0;
if (y != expected) {
errln("ts1.compareTo(ts2) returned " + x + ", expected "
+ relation(expected, "") + "0"
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
long t1 = ts1.getTime();
long t2 = ts2.getTime();
int z = (t1 > t2) ? 1 : (t1 < t2) ? -1 : 0;
if (z == 0) {
int n1 = ts1.getNanos();
int n2 = ts2.getNanos();
z = (n1 > n2) ? 1 : (n1 < n2) ? -1 : 0;
}
if (z != expected) {
errln("ts1.getTime() " + relation(z, "==") + " ts2.getTime(), expected "
+ relation(expected, "==")
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
}
示例10: test28
import java.sql.Timestamp; //导入方法依赖的package包/类
@Test
public void test28() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
java.util.Date ts2 = new java.util.Date(ts1.getTime());
assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
}
示例11: test31
import java.sql.Timestamp; //导入方法依赖的package包/类
@Test
public void test31() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Date d = new Date(ts1.getTime());
assertFalse(ts1.equals(d), "Error ts1 != d");
}
示例12: setTimestamp
import java.sql.Timestamp; //导入方法依赖的package包/类
/**
* <!-- start generic documentation -->
* Sets the designated parameter to the given <code>java.sql.Timestamp</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code> value,
* which the driver then sends to the database. With a
* <code>Calendar</code> object, the driver can calculate the timestamp
* 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.<p>
*
* When this method is used to set a parameter of type TIME or
* TIME WITH TIME ZONE, then the nanosecond value of the Timestamp object
* is used if the TIME parameter accepts fractional seconds.
*
* </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 timestamp
* @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 setTimestamp(int parameterIndex, Timestamp x,
Calendar cal) throws SQLException {
checkSetParameterIndex(parameterIndex, false);
int i = parameterIndex - 1;
if (x == null) {
parameterValues[i] = null;
return;
}
Type outType = parameterTypes[i];
long millis = x.getTime();
int zoneOffset = 0;
if (cal != null) {
zoneOffset = HsqlDateTime.getZoneMillis(cal, millis);
}
switch (outType.typeCode) {
case Types.SQL_TIMESTAMP :
millis += zoneOffset;
zoneOffset = 0;
// fall through
case Types.SQL_TIMESTAMP_WITH_TIME_ZONE :
parameterValues[i] = new TimestampData(millis / 1000,
x.getNanos(), zoneOffset / 1000);
break;
case Types.SQL_TIME :
millis += zoneOffset;
zoneOffset = 0;
// fall through
case Types.SQL_TIME_WITH_TIME_ZONE :
parameterValues[i] = new TimeData((int) (millis / 1000),
x.getNanos(), zoneOffset / 1000);
break;
default :
throw Util.sqlException(ErrorCode.X_42561);
}
}
示例13: test30
import java.sql.Timestamp; //导入方法依赖的package包/类
@Test
public void test30() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
java.util.Date d = new Timestamp(ts1.getTime());
assertTrue(ts1.equals(d), "Error ts1 != d");
}
示例14: testBug5874
import java.sql.Timestamp; //导入方法依赖的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);
}
}
示例15: overlap
import java.sql.Timestamp; //导入方法依赖的package包/类
public boolean overlap(Timestamp timestamp) {
return (from()==null || timestamp.getTime() >= this.from().getTime()) &&
(to()==null || timestamp.getTime() <= this.to().getTime());
}