{
rows: [
["Lisa", 16, "Female", "2000-12-01"],
["Bob", 22, "Male", "1996-01-21"]
],
{name: "name", note: ''},
{name: "age", note: ''},
{name: "gender", note: ''},
{name: "birthday", note: ''}
]
}

[
{name: "Lisa", age: 16, gender: "Female", birthday: "2000-12-01"},
{name: "Bob", age: 22, gender: "Male", birthday: "1996-01-21"},
]

1）输入日期2016-02-01，返回结果为2-1，表示2016年2月1日属于2月的第一周；
2）输入日期2016-09-01，返回结果为8-5，表示2016年9月1日属于8月的第五周。
（这里计算一周是从周一到当周周天算为一周；某天是属于某月的某一周的。以2016年4月为例：4月4日至10日为4月的第一周；4月1日至3日不属于4月的周次，而是归入3月计算。）

{id: 10001, name: "Lisa", age: 16},
{id: 10002, name: "Bob", age: 22},
{id: 10003, name: "Alice", age: 20},
];

{id: 10001, gender: "Female"},
{id: 10002, name: "Bob King", birthday: "1996-01-22"},
{id: 10005, name: "Tom", birthday: "2000-01-01"},
];

[
{id: 10001, name: "Lisa", age: 16, gender: "Female"},
{id: 10002, name: "Bob King", birthday: "1996-01-22", age: 22},
{id: 10003, name: "Alice", age: 20},
{id: 10005, name: "Tom", birthday: "2000-01-01"},
]

3个回答

``````/**
* 获取指定日期所在月的第一天
* @param c
* @return
*/
public static Calendar getFirstDayOfMonthCalendar(Calendar c){
Calendar firstDayOfMonthCalendar = Calendar.getInstance();
firstDayOfMonthCalendar.setTimeInMillis(c.getTimeInMillis());
firstDayOfMonthCalendar.set(Calendar.DAY_OF_MONTH, 1);
return firstDayOfMonthCalendar;
}
/**
* 获取指定日期所在月的第一个星期一
* @param c
* @return
*/
public static Calendar getFirstMondayOfMonthCalendar(Calendar c){
Calendar firstDayOfMonthCalendar = getFirstDayOfMonthCalendar(c);
Calendar firstMondayOfMonthCalendar = firstDayOfMonthCalendar;
int dayOfWeek = firstDayOfMonthCalendar.get(Calendar.DAY_OF_WEEK);
if(dayOfWeek==1){
}else if(dayOfWeek==2){

}else{
}
return firstMondayOfMonthCalendar;
}

/**
* 2: 判断给定的日期是几月的第几周
* @param dateStr yyyy-MM-dd
* @return
* @throws ParseException
*/
public static String getWeekOfMonth(String dateStr) throws ParseException{
//生成指定日期
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(dateStr);
Calendar c = Calendar.getInstance();
c.setTime(date);
//
int month = c.get(Calendar.MONTH);
int week = 1;
//获取指定日期所在月的第一个星期一
Calendar firstMondayOfMonthCalendar = getFirstMondayOfMonthCalendar(c);
System.out.println("firstMondayOfMonthCalendar:"+new Date(firstMondayOfMonthCalendar.getTimeInMillis()));
//比较指定日期和第一个星期一
if(c.compareTo(firstMondayOfMonthCalendar)==0){
//指定日期 = 第一个星期一
week=1;
}else{
if(c.compareTo(firstMondayOfMonthCalendar)>0){
//指定日期 > 第一个星期一 不处理
}else{
//指定日期 < 第一个星期一,为上一个月
month = firstMondayOfMonthCalendar.get(Calendar.MONTH);
firstMondayOfMonthCalendar = getFirstMondayOfMonthCalendar(firstMondayOfMonthCalendar);
}
//计算当前日期与 第一个星期一的差值
long moreDay = (c.getTimeInMillis()-firstMondayOfMonthCalendar.getTimeInMillis())/(3600*24*1000);
System.out.println("moreDay:"+moreDay);
week = week+(int)(moreDay/7);
}
return dateStr+"是第"+(month+1)+"月第"+week+"周";
}
``````