java 获取iso 标准的日期的第几周
发布网友
发布时间:2022-05-15 20:37
我来回答
共2个回答
热心网友
时间:2024-02-27 18:12
要获得第几周的信息,可以使用Calendar类的get方法,并将参数指定为 Calendar.WEEK_OF_MONTH或者WEEK_OF_YEAR
例子代码
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println("Current week of month: " + cal.get(Calendar.WEEK_OF_MONTH));
System.out.println("Current week of year: " + cal.get(Calendar.WEEK_OF_YEAR));
}
}
热心网友
时间:2024-02-27 18:12
import java.util.Date;
import java.text.SimpleDateFormat;
public class Test{
public static void main(String[] args){
//完整格式: yyyy-MM-dd HH:mm:ss E
//完整输出:2016-01-16 00:01:06 星期六
SimpleDateFormat sim = new SimpleDateFormat("E");
String week = sim.format(new Date());
System.out.println(week);
}
}