日期:2014-05-20  浏览次数:20838 次

如何判断一年中的某一个周是从几号到几号啊?
如题,或者怎么判断当前日期所在的周是从几号到几号
谢谢

------解决方案--------------------
数据库里有DATE  JAVA里有CALENDAR 都是系统日历的映射
------解决方案--------------------
随便写了个:
public static void main(String[] str) {
Calendar cal = GregorianCalendar.getInstance();
Date date = toDate( "20070828 ", "yyyyMMdd ");
cal.setTime(date);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
// 开始日
System.out.println(getDayAfter(date, -(weekday - 1)));
// 结束日
System.out.println(getDayAfter(date, 7 - weekday));
}

public static Date getDayAfter(Date dateFrom, int amount) {
long times = dateFrom.getTime();
long dateMillSec = 24l * 60 * 60 * 1000 * amount;
times = times + dateMillSec;
return new Date(times);
}

/**
*
* @param sDate string=> date
* @param sFmt format
* @return Date
*/
public static Date toDate(String sDate, String sFmt) {
Date dt = null;
try {
dt = new SimpleDateFormat(sFmt).parse(sDate);
} catch (ParseException e) {
return dt;
}
return dt;
}
------解决方案--------------------
Calendar calendar = Calendar.getInstance();
System.out.printf( "今天是:%tF%n ", calendar);

calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
System.out.printf( "本周的第一天(星期日)是:%tF%n ", calendar);

calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
System.out.printf( "本周的最后一天(星期六)是:%tF%n ", calendar);