自动加载下拉列表年月周
Posted 八月长安个人专栏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动加载下拉列表年月周相关的知识,希望对你有一定的参考价值。
public class Utils
/**
* 得到下拉的年份
*
* @return
*/
public static Map<String, Object> getSelectYear()
Map<String, Object> defaultYear = new LinkedHashMap<String, Object>();
defaultYear.put("2014", 2014);
defaultYear.put("2015", 2015);
defaultYear.put("2016", 2016);
int nowYear = Calendar.getInstance().get(Calendar.YEAR);// 获取当前年
if (nowYear <= 2016)
return defaultYear;
else
for (int i = 1; i <= nowYear - 2016; i++)
defaultYear.put(2016 + i + "", 2016 + i);
return defaultYear;
/**
* 获取下拉的月份
*
* @return
*/
public static Map<String, Object> getSelectMonth()
Map<String, Object> month = new LinkedHashMap<String, Object>();
for (int i = 1; i <= 12; i++)
month.put(i + "", i);
return month;
/**
* 获取下拉的周. <br/>
*
* @return
*/
public static Map<String, Object> getSelectWeek(int year,int month)
Calendar now = Calendar.getInstance();
now.set(Calendar.YEAR, year);
now.set(Calendar.MONTH, month-1);
Map<String, Object> defaultWeek = new LinkedHashMap<String, Object>();
defaultWeek.put("1", "第1周");
defaultWeek.put("2", "第2周");
defaultWeek.put("3", "第3周");
defaultWeek.put("4", "第4周");
int zhou = now.getActualMaximum(Calendar.WEEK_OF_MONTH);
if (zhou <= 4)
return defaultWeek;
else
for (int i = 1; i <= zhou - 4; i++)
defaultWeek.put((4 + i)+"", "第" + (4 + i) + "周");
System.out.println(defaultWeek);
return defaultWeek;
以上是关于自动加载下拉列表年月周的主要内容,如果未能解决你的问题,请参考以下文章
根据当前时间显示下拉列表的年月,需要显示之前六个月,用JS怎么来弄?
jsp表单,三个年月日下拉列表~ request接受到了三个参数~分别是年月日~ 怎样把3个参数变成日期型