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

📄 managedate.java

📁 本源码为教学管理信息系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	* @return String	*/	public static String getDayOfWeek(String sdate, String fmt) {		SimpleDateFormat df = new SimpleDateFormat(fmt);		java.util.Date date = null;		Calendar cal1 = Calendar.getInstance();		String chiweek = null;		try {			date = df.parse(sdate);		} catch (ParseException e) {			e.printStackTrace();		}		//设置时间		cal1.setTime(date);		int bh = cal1.get(Calendar.DAY_OF_WEEK);		switch (bh) {			case 1 :				chiweek = "星期日";				break;			case 2 :				chiweek = "星期一";				break;			case 3 :				chiweek = "星期二";				break;			case 4 :				chiweek = "星期三";				break;			case 5 :				chiweek = "星期四";				break;			case 6 :				chiweek = "星期五";				break;			case 7 :				chiweek = "星期六";				break;		}		return chiweek;	}	/**	* 获得系统的当前年度	* @return String	*/	public static String getYear() {		return DTFormat(getCurDate(), "yyyy");	}	/**	* 获得系统的当前月份	* @return String	*/	public static String getMonth() {		return DTFormat(getCurDate(), "MM");	}	/**	* 获得系统的当前日	* @return String	*/	public static String getDay() {		return DTFormat(getCurDate(), "dd");	}	/**	* 获得系统的当前年度	* @return String	*/	public static int _getYear() {		return Integer.parseInt(DTFormat(getCurDate(), "yyyy"));	}	/**	* 获得系统的当前月份	* @return String	*/	public static int _getMonth() {		return Integer.parseInt(DTFormat(getCurDate(), "MM"));	}	public static String getMonthString() {		return DTFormat(getCurDate(), "MM");	}	/**	* 获得系统的当前日	* @return String	*/	public static int _getDay() {		return Integer.parseInt(DTFormat(getCurDate(), "dd"));	}	/**	 * 获得指定日期是今年的第几周	 */	public static int getWeekOfYear(Date date) {					Calendar cal = Calendar.getInstance();		cal.setTime(date);		return cal.get(Calendar.WEEK_OF_YEAR);	}	/**	 * 获得指定日期是本月的第几周	 */	public static int getWeekOfMonth(Date date) {					Calendar cal = Calendar.getInstance();		cal.setTime(date);		return cal.get(Calendar.WEEK_OF_MONTH);	}	/**	 * 获得当前日期是今年的第几周	 */	public static int getWeekOfYear() {		return getWeekOfYear(getCurDate());	}	/**	 * 获得当前日期是今年的第几周	 */	public static int getRelWeekOfYear() {		return getWeekOfYear(getRelDate(getCurDate(), -7));	}	/**	 * 获得指定年有多少周	 */	public static int getWeekNumbersOfYear(int year) {		GregorianCalendar cal = new GregorianCalendar(year,12,31);		return cal.getMaximum(GregorianCalendar.WEEK_OF_YEAR);	}		/**	 * 获得指定日期是哪年哪月第几周,区分划分到上月和下月的周	 * @throws ParseException author zmx 2006.04.01	 */	public static String getWeekOfCurrentYearMonth(Date date){			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");		String date_temp= df.format(date);		String rtn = "";				Calendar cal = Calendar.getInstance();		cal.setTime(date);		int week = cal.get(Calendar.WEEK_OF_MONTH);//当前周		int chiweek = cal.get(Calendar.DAY_OF_WEEK);//当前星期				Date pre_day = getRelDate(date,-1);//当前日期前一天		cal.setTime(pre_day);				int pre_week = cal.get(Calendar.WEEK_OF_MONTH);	//前一天周					String lastday_temp =  getLastDate(Integer.valueOf(date_temp.substring(0,4)).intValue(),Integer.valueOf(date_temp.substring(5,7)).intValue());		String lastday = lastday_temp.substring(0,4)+"-"+lastday_temp.substring(5,7)+"-"+lastday_temp.substring(8,10);				Date last_day=null;		try {			last_day = df.parse(lastday);//本月最后一天		} catch (ParseException e) {			e.printStackTrace();		}				cal.setTime(last_day);				int last_week = cal.get(Calendar.WEEK_OF_MONTH);//最后一天周		int last_chiweek = cal.get(Calendar.DAY_OF_WEEK);//最后一天星期				Date next_month_day = getRelDate(last_day,1);//本月最后一天的下一天,即下月初第一天				String firstday = date_temp.substring(0,8)+"01";				Date first_day=null;		try {			first_day = df.parse(firstday);//本月第一天		} catch (ParseException e) {			e.printStackTrace();		}				cal.setTime(first_day);				int first_chiweek = cal.get(Calendar.DAY_OF_WEEK);//本月第一天星期				Date first_pre_day = getRelDate(first_day,-1);//本月第一天前一天		cal.setTime(first_pre_day);				int first_pre_week = cal.get(Calendar.WEEK_OF_MONTH);	//本月第一天前一天周			switch (week) {			case 1 :				if (chiweek == 5 || chiweek == 6 || chiweek==7 ){					if (first_chiweek == 5 || first_chiweek == 6 || first_chiweek==7 ){						rtn = df.format(first_pre_day).substring(0,4)+"-"+df.format(first_pre_day).substring(5,7)+";"+first_pre_week;					}else{						rtn = df.format(pre_day).substring(0,4)+"-"+df.format(pre_day).substring(5,7)+";"+pre_week;					}				}else{					rtn = date_temp.substring(0,7)+";"+week;				}				break;			case 2 :			case 3 :			case 4 :				if (first_chiweek == 5 || first_chiweek == 6 || first_chiweek==7 ){					int week_temp = week - 1;					rtn = date_temp.substring(0,7)+";"+week_temp;				}else{					rtn = date_temp.substring(0,7)+";"+week;				}				break;			case 5 :				if (week !=last_week){					if (first_chiweek == 5 || first_chiweek == 6 || first_chiweek==7 ){						int week_temp = week - 1;						rtn = date_temp.substring(0,7)+";"+week_temp;					}else{						rtn = date_temp.substring(0,7)+";"+week;					}				}else{					if (last_chiweek == 2 || last_chiweek == 3){						rtn = df.format(next_month_day).substring(0,4)+"-"+df.format(next_month_day).substring(5,7)+";"+"1";					}else{						rtn = date_temp.substring(0,7)+";"+week;					}				}  				break;			case 6 :				if (chiweek == 1 || chiweek == 2 || chiweek==3 ){					rtn = df.format(next_month_day).substring(0,4)+"-"+df.format(next_month_day).substring(5,7)+";"+"1";				}else{					rtn = date_temp.substring(0,7)+";"+week;				}				break;		}		return rtn;	}	/**	 * 获得指定日期是本月的第几周,区分划分到上月和下月的周	 * @throws ParseException author zmx 2006.04.01	 */	public static int getWeekOfCurrentMonth(Date date){			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");		String date_temp= df.format(date);		int rtn = 0;				Calendar cal = Calendar.getInstance();		cal.setTime(date);		int week = cal.get(Calendar.WEEK_OF_MONTH);//当前周		int chiweek = cal.get(Calendar.DAY_OF_WEEK);//当前星期				Date pre_day = getRelDate(date,-1);//当前日期前一天		cal.setTime(pre_day);				int pre_week = cal.get(Calendar.WEEK_OF_MONTH);	//前一天周					String lastday_temp =  getLastDate(Integer.valueOf(date_temp.substring(0,4)).intValue(),Integer.valueOf(date_temp.substring(5,7)).intValue());		String lastday = lastday_temp.substring(0,4)+"-"+lastday_temp.substring(5,7)+"-"+lastday_temp.substring(8,10);		Date last_day=null;		try {			last_day = df.parse(lastday);//本月最后一天		} catch (ParseException e) {			e.printStackTrace();		}		cal.setTime(last_day);				int last_week = cal.get(Calendar.WEEK_OF_MONTH);//最后一天周		int last_chiweek = cal.get(Calendar.DAY_OF_WEEK);//最后一天星期				Date next_month_day = getRelDate(last_day,1);//本月最后一天的下一天,即下月初第一天				String firstday = date_temp.substring(0,8)+"01";		Date first_day=null;		try {			first_day = df.parse(firstday);//本月第一天		} catch (ParseException e) {			e.printStackTrace();		}		cal.setTime(first_day);				int first_chiweek = cal.get(Calendar.DAY_OF_WEEK);//本月第一天星期				Date first_pre_day = getRelDate(first_day,-1);//本月第一天前一天		cal.setTime(first_pre_day);				int first_pre_week = cal.get(Calendar.WEEK_OF_MONTH);	//本月第一天前一天周					switch (week) {			case 1 :				if (chiweek == 5 || chiweek == 6 || chiweek==7 ){					if (first_chiweek == 5 || first_chiweek == 6 || first_chiweek==7 ){						rtn = first_pre_week;					}else{						rtn = pre_week;					}				}else{					rtn = week;				}				break;			case 2 :			case 3 :			case 4 :				if (first_chiweek == 5 || first_chiweek == 6 || first_chiweek==7 ){					int week_temp = week - 1;					rtn = week_temp;				}else{					rtn = week;				}				break;			case 5 :				if (week !=last_week){					if (first_chiweek == 5 || first_chiweek == 6 || first_chiweek==7 ){						rtn = week - 1;					}else{						rtn = week;					}				}else{					if (last_chiweek == 2 || last_chiweek == 3){						rtn = 1;					}else{						rtn = week;					}				}				break;			case 6 :				if (chiweek == 1 || chiweek == 2 || chiweek==3 ){					rtn = 1;				}else{					rtn = week;				}				break;		}		return rtn;	}}

⌨️ 快捷键说明

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