- 论坛徽章:
- 0
|
public class WhichWeek {
public static void main(String[] args) {
//基数日期,例如 2006年9月3号
Calendar calBase = Calendar.getInstance();
calBase.set(2006, 9 - 1, 3);
//当前日期,这里取 JVM 运行机器的日期,
// 如果要取数据库日期,可以使用 Oracle 的 SYSDATE 取得。
// 然后用 Calendar 类的 setTimeInMillis() 方法设置日期
Calendar calCurrent = Calendar.getInstance();
//取基数日期和当前日期各为各自年中的第几周
int weekBase = calBase.get(Calendar.WEEK_OF_YEAR);
int weekCurrent = calCurrent.get(Calendar.WEEK_OF_YEAR);
int weekCount = weekCurrent - weekBase;
System.out.println("本周是自" +
calBase.get(Calendar.YEAR) + "年" +
(calBase.get(Calendar.MONTH) + 1) + "月" +
calBase.get(Calendar.DAY_OF_MONTH) + "日" +
"以来的第" + weekCount + "周");
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/49841/showart_414055.html |
|