Java取时间程序
来源:百度知道 编辑:UC知道 时间:2024/05/17 10:25:37
oracle数据库
如果可以用.补50分.
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 + "周&quo