java手写万年日历源码实现

这是本人通过java语言编写的万年日历,可能看起来好复杂!
package com.lianhua.common;
/**
 * 页面日历实体类
 * @author lw
 *
 */
public class CalenderEntity {
	private Integer a1;//dd
	private String date1;//yyyy-MM-dd
	private Integer a2;
	private String date2;
	private Integer a3;
	private String date3;
	private Integer a4;
	private String date4;
	private Integer a5;
	private String date5;
	private Integer a6;
	private String date6;
	private Integer a7;
	private String date7;

	public String getDate1() {
		return date1;
	}

	public void setDate1(String date1) {
		this.date1 = date1;
	}

	public String getDate2() {
		return date2;
	}

	public void setDate2(String date2) {
		this.date2 = date2;
	}

	public String getDate3() {
		return date3;
	}

	public void setDate3(String date3) {
		this.date3 = date3;
	}

	public String getDate4() {
		return date4;
	}

	public void setDate4(String date4) {
		this.date4 = date4;
	}

	public String getDate5() {
		return date5;
	}

	public void setDate5(String date5) {
		this.date5 = date5;
	}

	public String getDate6() {
		return date6;
	}

	public void setDate6(String date6) {
		this.date6 = date6;
	}

	public String getDate7() {
		return date7;
	}

	public void setDate7(String date7) {
		this.date7 = date7;
	}

	public Integer getA1() {
		return a1;
	}

	public void setA1(Integer a1) {
		this.a1 = a1;
	}

	public Integer getA2() {
		return a2;
	}

	public void setA2(Integer a2) {
		this.a2 = a2;
	}

	public Integer getA3() {
		return a3;
	}

	public void setA3(Integer a3) {
		this.a3 = a3;
	}

	public Integer getA4() {
		return a4;
	}

	public void setA4(Integer a4) {
		this.a4 = a4;
	}

	public Integer getA5() {
		return a5;
	}

	public void setA5(Integer a5) {
		this.a5 = a5;
	}

	public Integer getA6() {
		return a6;
	}

	public void setA6(Integer a6) {
		this.a6 = a6;
	}

	public Integer getA7() {
		return a7;
	}

	public void setA7(Integer a7) {
		this.a7 = a7;
	}

}

 

日历实现类:

 

 

 

package com.lianhua.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public class ViewMonth {

	/** 月的第一天周几 */
	public static int getMonthFirstDay(Calendar c, int i) {
		// i = 0 是本月 1 上一月
		// Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, -i);
		c.set(Calendar.DAY_OF_MONTH, 1);
		return c.get(Calendar.DAY_OF_WEEK);
	}

	/** 月的最后一天周几 */
	public static int getMonthLastDay(int i, Calendar c) {

		// i = 0 是本月 1 上一月
		// Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, -i);
		c.set(Calendar.DAY_OF_MONTH, 1);
		c.roll(Calendar.DAY_OF_MONTH, -1);

		return c.get(Calendar.DAY_OF_WEEK);
	}

	// 当天日期
	public static int getDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.DAY_OF_MONTH);
	}

	// 当前月天数
	public static int getCurrentMonthDay(Calendar a) {

		a.set(Calendar.DATE, 1);
		a.roll(Calendar.DATE, -1);
		int maxDate = a.get(Calendar.DATE);
		return maxDate;
	}

	public static Calendar getDateOfLastOrNextMonth(Calendar date, int i) {
		Calendar date1 = (Calendar) date.clone();
		date1.add(Calendar.MONTH, i); // i=1 下一月的同一天 i=-1上一个月的同一天
		return date1;
	}

	public static Calendar getDateOfLastOrNextMonth(Date date, int i) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return getDateOfLastOrNextMonth(c, i);
	}

	// 当天周几
	public static int getWeek(Date date) {
		Calendar c = Calendar.getInstance();
		SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd");// yyyy-MM-dd
		// Date curDate = d.parse("2015-8-7");
		c.setTime(date);
		return c.get(Calendar.DAY_OF_WEEK);
	}

	/** * 使用此方法打印该月的日历. */
	public static List<CalenderEntity> printMonth(Calendar c) { /* 将该月份起始处的天数留空. */

		// c.setTime(date);
		int curMonthDays = getCurrentMonthDay(c);// c.getMaximum(Calendar.DAY_OF_MONTH);//
													// 获取当月天数
		int first = getMonthFirstDay(c, 0);
		int last = getMonthLastDay(0, c);
		int before = first - 1;
		int after = 7 - last;
		int countNum = curMonthDays + before + after;
		int entityNum = countNum / 7;// 5
		int abc = 1;
		int days = 0;
		int z = 0;
		List<CalenderEntity> list = new ArrayList<CalenderEntity>();
		for (int i = 0; i < entityNum; i++) {
			days += 7;
			CalenderEntity ce = new CalenderEntity();
			if (i == (entityNum - 1)) {
				for (int jj = curMonthDays - last + 1; jj <= curMonthDays; jj++) {
					if (jj <= curMonthDays) {
						if (abc == 1) {
							ce.setA1(jj);
							ce.setDate1(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							abc++;
						} else if (abc == 2) {
							ce.setA2(jj);
							ce.setDate2(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							abc++;
						} else if (abc == 3) {
							ce.setA3(jj);
							ce.setDate3(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							abc++;
						} else if (abc == 4) {
							ce.setA4(jj);
							ce.setDate4(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							abc++;
						} else if (abc == 5) {
							ce.setA5(jj);
							ce.setDate5(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							abc++;
						} else if (abc == 6) {
							ce.setA6(jj);
							ce.setDate6(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							abc++;
						} else if (abc == 7) {
							ce.setA7(jj);
							ce.setDate7(c.get(Calendar.YEAR) + "-"
									+ (c.get(Calendar.MONTH) + 1) + "-" + jj);
							// abc = 1;
						}
					}

				}

			} else {
				for (int j = days - 6; j <= days; j++) {
					switch (first) {
					case Calendar.WEDNESDAY:// 4
						z = j - 3;
						if (z <= curMonthDays) {
							if (i == 0) {
								if (abc == 1 || abc == 2 || abc == 3) {
									// ce.setA1(null);
									// ce.setDate1(null);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}

							} else {
								if (abc == 1) {
									ce.setA1(z);
									ce.setDate1(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}
							}

						}

						break;
					case Calendar.SUNDAY:// 1
						z = j;
						if (z <= curMonthDays) {

							if (abc == 1) {
								ce.setA1(z);
								ce.setDate1(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc++;
							} else if (abc == 2) {
								ce.setA2(z);
								ce.setDate2(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc++;
							} else if (abc == 3) {
								ce.setA3(z);
								ce.setDate3(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc++;
							} else if (abc == 4) {
								ce.setA4(z);
								ce.setDate4(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc++;
							} else if (abc == 5) {
								ce.setA5(z);
								ce.setDate5(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc++;
							} else if (abc == 6) {
								ce.setA6(z);
								ce.setDate6(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc++;
							} else if (abc == 7) {
								ce.setA7(z);
								ce.setDate7(c.get(Calendar.YEAR) + "-"
										+ (c.get(Calendar.MONTH) + 1) + "-" + z);
								abc = 1;
							}

						}

						break;
					case Calendar.MONDAY:// 2
						z = j - 1;
						if (z <= curMonthDays) {
							if (i == 0) {
								if (abc == 1) {
									// ce.setA1(null);
									// ce.setDate1(null);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}

							} else {
								if (abc == 1) {
									ce.setA1(z);
									ce.setDate1(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}
							}

						}

						break;
					case Calendar.TUESDAY:// 3
						z = j - 2;
						if (z <= curMonthDays) {
							if (i == 0) {
								if (abc == 1 || abc == 2) {
									// ce.setA1(null);
									// ce.setDate1(null);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}

							} else {
								if (abc == 1) {
									ce.setA1(z);
									ce.setDate1(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}
							}

						}

						break;
					case Calendar.THURSDAY:// 5
						z = j - 4;
						if (z <= curMonthDays) {
							if (i == 0) {
								if (abc == 1 || abc == 2 || abc == 3
										|| abc == 4) {
									// ce.setA1(null);
									// ce.setDate1(null);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}

							} else {
								if (abc == 1) {
									ce.setA1(z);
									ce.setDate1(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);

									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}
							}

						}

						break;

					case Calendar.FRIDAY:// 6
						z = j - 5;
						if (z <= curMonthDays) {
							if (i == 0) {
								if (abc == 1 || abc == 2 || abc == 3
										|| abc == 4 || abc == 5) {
									// ce.setA1(null);
									// ce.setDate1(null);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}

							} else {
								if (abc == 1) {
									ce.setA1(z);
									ce.setDate1(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									if (z == 26) {
										System.out.println(z);
									}
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}
							}

						}

						break;
					case Calendar.SATURDAY:// 7
						z = j - 6;
						if (z <= curMonthDays) {
							if (i == 0) {
								if (abc == 1 || abc == 2 || abc == 3
										|| abc == 4 || abc == 5 || abc == 6) {
									// ce.setA1(null);
									// ce.setDate1(null);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}

							} else {
								if (abc == 1) {
									ce.setA1(z);
									ce.setDate1(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 2) {
									ce.setA2(z);
									ce.setDate2(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 3) {
									ce.setA3(z);
									ce.setDate3(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 4) {
									ce.setA4(z);
									ce.setDate4(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 5) {
									ce.setA5(z);
									ce.setDate5(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 6) {
									ce.setA6(z);
									ce.setDate6(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc++;
								} else if (abc == 7) {
									ce.setA7(z);
									ce.setDate7(c.get(Calendar.YEAR) + "-"
											+ (c.get(Calendar.MONTH) + 1) + "-"
											+ z);
									abc = 1;
								}
							}

						}

						break;

					}

				}
			}

			list.add(ce);
		}

		return list;
	}

	public static void main(String[] args) {
		Calendar c = Calendar.getInstance();

		SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd");// yyyy-MM-dd
		// HH:mm:ss
		try {
			Date curDate = d.parse("2015-8-7");//输入年月日或者年月即可获取当前月的日历

			// System.out.println(curDate);
			c.setTime(curDate);
			// System.out.println(c.get(Calendar.DAY_OF_WEEK));
			/*
			 * List<CalenderEntity> list = printMonth(curDate);
			 * System.out.println(list.size()); for (int i = 0; i < list.size();
			 * i++) {
			 * System.out.println(list.get(i).getA1()+"("+list.get(i).getDate1
			 * ()+")" + "\t" +
			 * list.get(i).getA2()+"("+list.get(i).getDate2()+")" + "\t" +
			 * list.get(i).getA3()+"("+list.get(i).getDate3()+")" + "\t" +
			 * list.get(i).getA4()+"("+list.get(i).getDate4()+")" + "\t" +
			 * list.get(i).getA5()+"("+list.get(i).getDate5()+")" + "\t" +
			 * list.get(i).getA6()+"("+list.get(i).getDate6()+")" + "\t" +
			 * list.get(i).getA7()+"("+list.get(i).getDate7()+")"); }
			 */
			// System.out.println(c.get(Calendar.DAY_OF_WEEK));
			// System.out.println(getMonthFirstDay(0));
			// System.out.println(getMonthLastDay(1));

			/*
			 * GregorianCalendar calendar = new GregorianCalendar(2014, 1, 29);
			 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//
			 * 定义日期显示格式
			 * 
			 * System.out.println(sdf.format(calendar.getTime()));//
			 * 打印当前月份的下一个月份
			 * 
			 * for (int i = 0; i < 1; i++) {
			 * 
			 * calendar.add(Calendar.MONTH, -1);// 获取上个月月份
			 * 
			 * System.out.println(sdf.format(calendar.getTime()));// 输出结果
			 * 
			 * }
			 */

			System.out.println(getDay(new Date()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值