Java判断一个日期
是否在
两个时间(HH:mm:ss)之内(跨天 例如今天的23点-明天的凌晨1点)
直接上代码,这里用到日期来比较的,也可以直接通过日期后面的
时间来比较,不需要加天数
public static boolean dataCompare(Date date, String strDateBegin, String strDateEnd) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
public class test4 {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm");// 设置日期格式
Date now = null;
Date beginTime = null;
Date endTime = null;
try...
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
if (nowTime.getTime() == startTime.getTime()
|| nowTime.getTime() == endTime.getTime()) {
return true;
Calendar date = Calendar.getInstance();
date.setTime(nowT
Java判断某个日期在两个日期范围内
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static void main(String[] args) throws ParseException {
//判...
public static boolean decideDateRange(String currentTime,String startTime,String endTime) {
boolean flg = false;
if (isNullOrEmpty(currentTime) || isNullOrEmpty(startTime) || isNullOrEmpty(endTime)) {
logger.error("传入的时间参数不能为空");
throw new Trans
1. 确定矩形的左上角和右下角
两个点的坐标(假设为(x1,y1)和(x2,y2))。
2.
判断点的坐标
是否在矩形的左侧、右侧、上方、下方。
3. 如果点在矩形的左侧、右侧、上方、下方
之外,那么它一定在矩形外面;否则,它在矩形内部。
具体实现代码如下:
public static boolean isPointInRectangle(int x, int y, int x1, int y1, int x2, int y2) {
if (x < x1 || x > x2) {
return false; // 在矩形左侧或右侧
if (y < y1 || y > y2) {
return false; // 在矩形上方或下方
return true; // 在矩形内部
其中,x和y是点的坐标,x1、y1是矩形左上角的坐标,x2、y2是矩形右下角的坐标。如果返回true,则表示点在矩形内部;否则,表示点在矩形外面。