after()函數是Java SQL的Timestamp類的一部分。該函數返回一個布爾值,該布爾值表示Timestamp對象是否出現在給定的Timestamp對象之後。
函數簽名:
public boolean after(Timestamp t)
用法:
ts1.after(ts2);
參數:該函數接受Timestamp對象作為要檢查的參數。
返回值:該函數返回布爾數據類型,該數據類型表示Timestamp對象是否出現在給定的Timestamp對象之後。
異常:該函數不會引發任何異常
以下示例說明了after()函數的使用
範例1:創建兩個非相等的時間戳記,並檢查第二個時間戳記是否在第一個時間戳記之後發生
// Java program to demonstrate the
// use of after() function
import java.sql.*;
public class solution {
public static void main(String args[])
{
// Create two timestamp objects
Timestamp ts1 = new Timestamp(10000);
Timestamp ts2 = new Timestamp(10001);
boolean b = ts2.after(ts1);
// Check if the second timestamp occurs
// after first timestamp
if (b) {
// If true print that the Second Timestamp
// occurs after the first timestamp
System.out.println("Second Timestamp occurs"
+ " after first timestamp");
}
else {
// If false print that the Second Timestamp
// does not occur after the first timestamp
System.out.println("Second Timestamp does not"
+ " occur after first timestamp");
}
}
}
輸出:
Second Timestamp occurs after first timestamp
範例2:創建兩個相等的時間戳,並檢查第二個時間戳是否出現在第一個時間戳之後
// Java program to demonstrate the
// use of after() function
import java.sql.*;
public class solution {
public static void main(String args[])
{
// Create two timestamp objects
Timestamp ts1 = new Timestamp(10000);
Timestamp ts2 = new Timestamp(10000);
boolean b = ts2.after(ts1);
// Check if the second timestamp occurs
// after first timestamp
if (b) {
// If true print that the Second Timestamp
// occurs after the first timestamp
System.out.println("Second Timestamp occurs"
+ " after first timestamp");
}
else {
// If false print that the Second Timestamp
// does not occur after the first timestamp
System.out.println("Second Timestamp does not"
+ " occur after first timestamp");
}
}
}
輸出:
Second Timestamp does not occur after first timestamp
參考: https:// docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html
相關用法
- Java SQL Timestamp before()用法及代碼示例
- Java SQL Timestamp setTime()用法及代碼示例
- Java SQL Timestamp getNanos()用法及代碼示例
- Java SQL Timestamp getTime()用法及代碼示例
- Java SQL Timestamp setNanos()用法及代碼示例
- Java UUID timestamp()用法及代碼示例
- Java Java.util.function.BiPredicate用法及代碼示例
- Java Java.util.function.DoublePredicate用法及代碼示例
- Java Java.util.function.LongPredicate用法及代碼示例
- Java Java.util.function.IntPredicate用法及代碼示例
- Java Function Interface用法及代碼示例
- Java Inflater inflate()用法及代碼示例
- Java ZipEntry setCrc()用法及代碼示例
- Java Inflater needsInput()用法及代碼示例
- Java Inflater getTotalOut()用法及代碼示例
注:本文由純淨天空篩選整理自andrew1234大神的英文原創作品 Java SQL Timestamp after() function with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。