⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonutils.java

📁 时间类型转换
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				Map currUser = new HashMap();
				currUser.put("userId", userId);
				currUser.put("branchId", jgbm);
				currUser.put("branchClass", orgClass);
				System.out.println("userId="+currUser.get("userId").toString()+" branchId="+currUser.get("branchId").toString()+" branchClass="+currUser.get("branchClass").toString());
				List cusManagerList = formService.getOtherOption("getCusManagerByOrgClass", currUser);
				if(cusManagerList!=null&&!cusComInfoService.getUserRole(userId).equalsIgnoreCase("1")){
					OptionsList ol = new OptionsList();
				    ol.setOptionLabel("");
				    ol.setOptionValue("") ;
				    cusManagerList.add(0,ol);
				}
				setOptions(form, managerFieldname, cusManagerList);		//editById来代替客户经理
			}
			if(isShowOrgList){
				Map currOrgList = new HashMap();
				currOrgList.put("userId", userId);
				currOrgList.put("branchId", jgbm);
				String orgType = personInf.getOrgClass();
				if(userId.equals("8888"))
					orgType = "topOrgNonCreditor";
				currOrgList.put("branchClass",orgType);
				List orgList = formService.getOtherOption("getOrgByClass", currOrgList);
				if(orgList!=null&&personInf.getOrgClass().equals("2")){
					OptionsList ol = new OptionsList();
				    ol.setOptionLabel("");
				    ol.setOptionValue("") ;
				    orgList.add(0,ol);
				}
				setOptions(form, orgFieldname, orgList);
			}
			return form;
		}
	**/
	public int getBetweenMonth(Date start,Date end){
    	String startDateStr = ts.dateToStr(start,"");
    	String endDateStr = ts.dateToStr(end,"");
    	int startYear=Integer.parseInt(startDateStr.substring(0,4));
		int endYear=Integer.parseInt(endDateStr.substring(0,4));
		int startMonth=Integer.parseInt(startDateStr.substring(4,6));
		int endMonth=Integer.parseInt(endDateStr.substring(4,6));
		int startDay=Integer.parseInt(startDateStr.substring(6,8));
		int endDay=Integer.parseInt(endDateStr.substring(6,8));
    	int betweenMonth = 0;
    	betweenMonth = (endYear-startYear)*12 + endMonth - startMonth;
    	if((endDay - startDay)>0)
    		betweenMonth++;
    	return betweenMonth;
    }

	public int containsLeepYearOverDaysCounts(Date startDate,Date endDate){
		int leepYearCounts = 0;
		String startDateStr = ts.dateToStr(startDate,"");
    	String endDateStr = ts.dateToStr(endDate,"");
    	int startYear=Integer.parseInt(startDateStr.substring(0,4));
		int endYear=Integer.parseInt(endDateStr.substring(0,4));
		int startMonth=Integer.parseInt(startDateStr.substring(4,6));
		int endMonth=Integer.parseInt(endDateStr.substring(4,6));
		int startDay=Integer.parseInt(startDateStr.substring(6,8));
		int endDay=Integer.parseInt(endDateStr.substring(6,8));
		int YearCount =  endYear-startYear;
		if(isLeepYear(startYear)){	//起始年份
			if(startMonth<=2&&startDay<=28){
				leepYearCounts ++;
			}
		}
		startYear++;
		for(int i=0;i<YearCount-1;i++){	 //中间年份
			if(isLeepYear(startYear)){
				leepYearCounts ++;
			}
			startYear++;
		}
		if(isLeepYear(endYear)&&(endYear!=startYear)){   //终止年份
			if(endMonth==2&&endDay>28)
				leepYearCounts ++;
			if(endMonth>2)
				leepYearCounts ++;
		}
		return leepYearCounts;
	}

	private boolean isLeepYear(int year){
		if((year%4==0 && year%100!=0)||(year%400==0))
			return true;
		else
			return false;
	}

	public boolean greaterThanGivenMonthCount(Date startDate,Date endDate,int stepMonth){
		String startDateStr = ts.dateToStr(startDate,"");
		String endDateStr = ts.dateToStr(endDate,"");
		int startYear=Integer.parseInt(startDateStr.substring(0,4));
		int endYear=Integer.parseInt(endDateStr.substring(0,4));
		int startMonth=Integer.parseInt(startDateStr.substring(4,6));
		int endMonth=Integer.parseInt(endDateStr.substring(4,6));
		int startDay=Integer.parseInt(startDateStr.substring(6,8));
		int endDay=Integer.parseInt(endDateStr.substring(6,8));
		int monthCount =  (endYear-startYear)*12+endMonth-startMonth;
		int leepYearCounts = containsLeepYearOverDaysCounts(startDate,endDate);
		System.out.println("leepYearCounts: "+leepYearCounts);
		System.out.println("endDay:"+endDay+"startDay:"+startDay);
		if(endDay>startDay){
			if((endDay-startDay-leepYearCounts)>0)
				monthCount++;
		}else{
			System.out.println("monthCount "+monthCount);
			if(monthCount==stepMonth+1){
				int daysInMonth = 0;
				switch (startMonth){
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
				case 12:
					daysInMonth=31;		break;
				case 4:
				case 6:
				case 9:
				case 11:
					daysInMonth=30;		break;
				case 2:
					daysInMonth = isLeepYear(startYear)? 29:28;		break;
				}
				if(endDay<=leepYearCounts&&(endDay+startDay==daysInMonth))
					monthCount--;
				System.out.println("daysInMonth: "+daysInMonth);
//				if(endDay+startDay>=daysInMonth)
//					monthCount--;
			}
		}
		System.out.println("相隔的月数未:"+monthCount);
		return monthCount>stepMonth? true:false;
	}

	/**
	* 获取两个日期间的所有每月的固定日期的数组
	*
	*/

	public Date[] getPlannedRepayDateArr(Date startDate,Date endDate,String plannedPayDay){
		int startYear = startDate.getYear();
		int endYear = endDate.getYear();
		int startMonth = startDate.getMonth()+1;//Integer.parseInt((ts.dateToStr(startDate)).substring(5,7));
		int endMonth = endDate.getMonth()+1;
		int endDay = endDate.getDay();
		int step = (endYear-startYear)*12+(endMonth-startMonth);
		if(endMonth<Integer.parseInt(plannedPayDay)){
			step -=1;
		}
		System.out.println("到期天数: "+endDay);
		Date betweenDates[] = new Date[step];
		System.out.println("step : "+step);
		if(Integer.parseInt(plannedPayDay) <10)
			plannedPayDay = "0"+Integer.parseInt(plannedPayDay);
		for(int i=0;i<step;i++){
			if(i!=step){

				if(++startMonth>12){
					startMonth=1;
					startYear++;
					betweenDates[i] = ts.strToDate(Integer.toString(1900+startYear)+"-01"+"-"+plannedPayDay);
				}else{
					if(startMonth<10)
						betweenDates[i] = ts.strToDate(Integer.toString(1900+startYear)+"-0"+startMonth+"-"+plannedPayDay);
					else
						betweenDates[i] = ts.strToDate(Integer.toString(1900+startYear)+"-"+startMonth+"-"+plannedPayDay);
				}
			}else{
				betweenDates[step] = endDate;
			}
		}
		return betweenDates;
	}

	private Properties loadNamedPropertiesFile(String propsFileName){
        Properties props = new Properties();
		try {
			System.out.println(getClass().getPackage().toString());
			java.io.InputStream is = getClass().getResourceAsStream("/" + propsFileName);
			props.load(is);
			is.close();
		} catch(FileNotFoundException fe){
			return null;
		} catch (IOException ie) {
			return null;
		}
        return props;
    }
	/**
	 * 获取给定“propsFileName” 中的 title对应的值串
	 * */
	public String getContentInProperties(String propsFileName,String title){
		Properties ctrlFlowProps = loadNamedPropertiesFile(propsFileName);
		String detailStr = null;
		if(ctrlFlowProps.containsKey(title)){
			detailStr = ctrlFlowProps.getProperty(title);
		}
		return detailStr;
	}

	public String getKeyInProperties(String propsFileName,String title){
		Properties ctrlFlowProps = loadNamedPropertiesFile(propsFileName);
		Set set = ctrlFlowProps.keySet();
		int itSize = set.size();
		Iterator it = set.iterator();
		String currKey = null;
		for(int i=0;i<itSize;i++){
			currKey = it.next().toString();
			if(ctrlFlowProps.getProperty(currKey).equals(title))
				return currKey;
			else
				currKey = null;
		}
		return currKey;
	}

	public String getLoanBizInCoreContent(String title){
		Properties ctrlFlowProps = loadNamedPropertiesFile("LoanBizInCore.properties");
		if(ctrlFlowProps.containsKey(title))
			return ctrlFlowProps.getProperty(title);
		else
			return "";
	}

	public Date intDateToDate(int dateInt){
		StringBuffer sb = new StringBuffer();
		String fromDate = new String(Integer.toString(dateInt));
		sb.append(fromDate.substring(0,4)).append("-").append(fromDate.substring(4,6)).append("-").append(fromDate.substring(6,8));
		return ts.strToDate(sb.toString());
	}
	public int dateToInt(Date date){
		return Integer.parseInt(ts.dateToStr(date,""));
	}
	
  	public String lastMonthDateStr(Calendar month, int times){
    	Calendar c = month ;
    	for(int i=0;i<times;i++){
    		if(c.getTime().getMonth()==0){
    			c.roll(Calendar.YEAR, -1) ;
    		}
        c.roll(Calendar.MONTH, -1) ;
        c.set(c.getTime().getYear()+1900, c.getTime().getMonth(), 1) ;
        c.roll(Calendar.DATE, -1) ;
    	}

        return ts.dateToStr(c.getTime(),"") ;
    }

  
    public void copyFile(String oldPathFile, String newPathFile) {
		InputStream inStream = null;
		FileOutputStream fs = null;
		File oldfile = null;
        try {
            int bytesum = 0;
            int byteread = 0;
            oldfile = new File(oldPathFile);
            if (oldfile.exists()) { //文件存在时
                inStream = new FileInputStream(oldPathFile); //读入原文件
                fs = new FileOutputStream(newPathFile);
                byte[] buffer = new byte[1444];
                while((byteread = inStream.read(buffer)) != -1){
                    bytesum += byteread; //字节数 文件大小
                    fs.write(buffer, 0, byteread);
                }
                fs.flush();
                fs.close();
                inStream.close();
                oldfile.delete();
            }
        }catch (Exception e) {
        }finally {
            try {
            	if(fs!=null)
            		fs.close();
            }
            catch (IOException ex1) {
            	ex1.printStackTrace();
            }
        }
    }

    public double getDoubleWithDigits(double orginDouble,int digits){
		BigDecimal tmp = new BigDecimal(orginDouble);
//		System.out.println(orginDouble + "取小数后面 " + digits + " 位: " + tmp.setScale(digits, 2));
    	return tmp.setScale(digits, 2).doubleValue();
    }

    public String getFormerDate(int appointedDay){
    	java.util.Date myDate=new java.util.Date();
		long myTime=(myDate.getTime()/1000)-60*60*24*7;
		SimpleDateFormat sbf =new SimpleDateFormat("yyyyMMdd");
		myDate.setTime(myTime*1000);
		return sbf.format(myDate);
    }

    /**
	 * <p>Description: 将"a|b|c|d|"格式的字符串转换为"a,b,c,d"形式</p>
	 * @return "a,b,c,d"形式
	 * @param oldStr:给定的原数据库中带有"|"的字段
	 */
	public String replaceChar4Field(String oldStr){
        if(oldStr.equalsIgnoreCase(""))
            return "";
	    String inter=oldStr.replace('|',',');
	    StringBuffer interField = new StringBuffer(inter);
	    interField.deleteCharAt(interField.lastIndexOf(","));
	    return interField.toString();
	}

	public static void main(String args[]){
		CommonUtils util = CommonUtils.getInstance();
	}
	
	public double noRound(double a,int b){
		double c=0;
		double d=Math.pow(10,b);
		c=(a*d)%1;
		if(c>0){
			a=(double)((int)(a*d)+1)/d;
		}
		else {
			a=(double)((int)(a*d))/d;
		}
		return a;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -