before()函數是Java SQL的Timestamp類的一部分。該函數返回一個布爾值,該布爾值表示Timestamp對象是否出現在給定的Timestamp對象之前。
函數簽名:
public boolean before(Timestamp t)
用法:
ts1.before(ts2);
參數:該函數接受Timestamp對象作為要檢查的參數。
返回值:該函數返回布爾數據類型,該數據類型表示Timestamp對象是否出現在給定的Timestamp對象之前。
異常:該函數不會引發任何異常
以下示例說明了before()函數的使用
範例1:創建兩個非相等的時間戳,並檢查第二個時間戳是否在第一個時間戳之前。
// Java program to demonstrate the
// use of before() function
import java.sql.*;
public class solution {
public static void main(String args[])
{
// Create two timestamp objects
Timestamp ts1 = new Timestamp(10003);
Timestamp ts2 = new Timestamp(10001);
boolean b = ts2.before(ts1);
// Check if the second timestamp occurs
// before first timestamp
if (b) {
// If true print that the Second Timestamp
// occurs before the first timestamp
System.out.println("Second Timestamp occurs"
+ " before first timestamp");
}
else {
// If false print that the Second Timestamp
// does not occur before the first timestamp
System.out.println("Second Timestamp does not occur"
+ " before first timestamp");
}
}
}
輸出:
Second Timestamp occurs before first timestamp
範例2:創建兩個相等的時間戳,並檢查第二個時間戳是否出現在第一個時間戳之前
// Java program to demonstrate the
// use of before() 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.before(ts1);
// Check if the second timestamp occurs
// before first timestamp
if (b) {
// If true print that the Second Timestamp
// occurs before the first timestamp
System.out.println("Second Timestamp occurs"
+ " before first timestamp");
}
else {
// If false print that the Second Timestamp
// does not occur before the first timestamp
System.out.println("Second Timestamp does not"
+ " occur before first timestamp");
}
}
}
輸出:
Second Timestamp does not occur before first timestamp
參考: https:// docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html
相關用法
- Java SQL Timestamp after()用法及代碼示例
- 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 before() function with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。