import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class GetWeek {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(getWeek(new Date()));
}
public static int getWeek(Date date) {
GregorianCalendar g = new GregorianCalendar();
g.setTime(date);
return g.get(Calendar.WEEK_OF_YEAR);//获得周数
}
}
import java.util.Calendar;
public class Tesat3 {
public static void main(String[] args) {
Calendar c=Calendar.getInstance();
int i = c.get(Calendar.WEEK_OF_YEAR);
System.out.println(i);
}
}
Calendar curr = Calendar.getInstance();
int week=curr.get(Calendar.WEEK_OF_YEAR);
System.out.println("今天是今年的第几周:"+week);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(format.format(System.currentTimeMillis()));
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(date);
System.out.println(calendar.get(Calendar.WEEK_OF_YEAR));
// jdk1.8 周日开一周第一天时
// ********格式化 每年的周数**************
int week = LocalDate.of(2019, 12, 30).get(WeekFields.ISO.weekOfWeekBasedYear());
int year = LocalDate.of(2019, 12, 30).get(WeekFields.ISO.weekBasedYear());
String formatWeek = new DecimalFormat("00").format(week);
System.out.println(year + "-" + formatWeek);// 2020-01
// ********格式化 每年的周数**************