wannianli.txt
来自「最简单的java万年历实现」· 文本 代码 · 共 32 行
TXT
32 行
HttpSession session = request.getSession();
//获取从页面传递过来的日期
String time = request.getParameter("time");
if (time == "") {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
time = sdf.format(new Date());
}
//截取年数
int year = Integer.parseInt(time.substring(0,4));
//截取月份
int month = Integer.parseInt(time.substring(5,7))-1;
//截取日期
int today = Integer.parseInt(time.substring(8));
//构造日历对象
GregorianCalendar calendar = new GregorianCalendar(year,month,today);
//将日历对象设置为这个月的第一天,并获得这一天为星期几。
calendar.set(Calendar.DAY_OF_MONTH, 1);
int weekday = calendar.get(Calendar.DAY_OF_WEEK);
Vector vectorday = new Vector();
for (int i = Calendar.MONDAY; i < weekday; i++) {
vectorday.add(" ");
}
session.setAttribute("today", today);
session.setAttribute("year", year);
session.setAttribute("month", month+1);
do {
int day = calendar.get(Calendar.DAY_OF_MONTH);
vectorday.add(day);
calendar.add(Calendar.DAY_OF_MONTH, 1);
} while (calendar.get(Calendar.MONTH) == month);
session.setAttribute("vectorday", vectorday);
response.sendRedirect("../index.jsp");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?