java.sql.timestamp_Java SQL Timestamp after()用法及代码示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值