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 Inflater inflate()用法及代码示例
- Java ZipEntry setCrc()用法及代码示例
- Java Inflater needsInput()用法及代码示例
- Java Inflater getTotalOut()用法及代码示例
注:本文由纯净天空筛选整理自andrew1234大神的英文原创作品 Java SQL Timestamp before() function with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。