JAVA请写一个函数,用于获取当前时间在今年的第几周

2024-11-30 01:01:00
推荐回答(2个)
回答1:

package com.test4;

import java.util.Calendar;
import java.util.Date;

public class Test5 {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
System.out.println(c.get(Calendar.WEEK_OF_YEAR));
}
}

回答2:

// ********格式化 每年的周数**************
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
// ********格式化 每年的周数**************