java timestamp 比较_Java运用时间戳对比两个时间的大小

Java运用时间戳对比两个时间的大小

在开发中,我们会常常要对比两个时间的大小,下面我们通过比较两个时间的时间戳来判断这两个时间的大小。

/***

* 比较两个时间

* @now Data 当前时间

* @validity Date 有效期

* @return 1:当前时间大于有效期;2:当前时间小于有效期

* */

public static int compareDate(Date now, Date validity) {

if(validity != null){

try {

if (now.getTime() > validity.getTime())

return 1;

else if (now.getTime() < validity.getTime())

return 2;

else

return 0;

} catch (Exception exception) {

exception.printStackTrace();

}

}

return 0;

}

Java运用时间戳对比两个时间的大小 在开发中,我们会常常要对比两个时间的大小,下面我们通过比较两个时间的时间戳来判断这两个时间的大小。 /*** * 比较两个时间 * @now Data 当前时间 * @validity Date 有效期 * @return 1:当前时间大于有效期;2:当前时间小于有效期 * */ public static int compareDate(Date now, Date validity) { if(validity != null){ try { if (now.getTime() > validity.getTime()) return 1; else if (now.getTime() < validity.getTime()) return 2; else return 0; } catch (Exception exception) { exception.printStackTrace(); } } return 0; }
经验分享 程序员 微信小程序 职场和发展