java/jsp获取当前时间是本年的第几周

1、方法一

public static void main(String[] args)

{
Calendar cal = Calendar.getInstance();
int week = cal.get(cal.WEEK_OF_YEAR);
System.out.println("今天是今年的第" + week + "周;");

}


2、方法二:

public static void main(String[] args)
{
Date date = new Date();
System.out.println(date.getTime());// 1493690652008
long time1 = date.getTime();
date.setMonth(0);
date.setDate(1);
long time2 = date.getTime();
long time = time1 - time2;
System.out.println(date);// Sun Jan 01 10:06:02 CST 2017
time = (time1 - time2) / 86400000 / 7 + 1;
System.out.println("今天是本年的第" + time + "周");
}

控制台输出:

今天是今年的第18周;


jsp方法:


你可能感兴趣的:(java/jsp获取当前时间是本年的第几周)