zoukankan      html  css  js  c++  java
  • 【JAVA】判断当前日期是否在时间点内

    public static boolean isInDate(Date date, String strDateBegin,
    		String strDateEnd) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String strDate = sdf.format(date);
    	// 截取当前时间时分秒
    	int strDateH = Integer.parseInt(strDate.substring(11, 13));
    	int strDateM = Integer.parseInt(strDate.substring(14, 16));
    	int strDateS = Integer.parseInt(strDate.substring(17, 19));
    	// 截取开始时间时分秒
    	int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
    	int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
    	int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
    	// 截取结束时间时分秒
    	int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
    	int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
    	int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
    	if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
    		// 当前时间小时数在开始时间和结束时间小时数之间
    		if (strDateH > strDateBeginH && strDateH < strDateEndH) {
    			return true;
    			// 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间
    		} else if (strDateH == strDateBeginH && strDateM >= strDateBeginM
    				&& strDateM <= strDateEndM) {
    			return true;
    			// 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间
    		} else if (strDateH == strDateBeginH && strDateM == strDateBeginM
    				&& strDateS >= strDateBeginS && strDateS <= strDateEndS) {
    			return true;
    		}
    		// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数
    		else if (strDateH >= strDateBeginH && strDateH == strDateEndH
    				&& strDateM <= strDateEndM) {
    			return true;
    			// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数
    		} else if (strDateH >= strDateBeginH && strDateH == strDateEndH
    				&& strDateM == strDateEndM && strDateS <= strDateEndS) {
    			return true;
    		} else {
    			return false;
    		}
    	} else {
    		return false;
    	}
    }
    

      

  • 相关阅读:
    Bug
    [转]C# 向web网站GET、POST 数据
    使用JavaScript触发ASP.NET Validator验证
    Asp.net 布尔运算符
    HTML 后退功能JS
    [转]C# 获取硬盘序列号 Volume Serial Number
    ASP.NET中,Gridview如何将源数据中的
    显示成回车

    ASP.NET 验证控件
    与或非的运算法则
    [转]WinForm开发,窗体显示和窗体传值相关知识总结
  • 原文地址:https://www.cnblogs.com/kedarui/p/6119293.html
Copyright © 2011-2022 走看看