Java实现 已知日期转化格式找星期数
代码如下:
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Test801 {
public static void main(String[] args) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy/MM/dd");
// 把字符串转化为 LocalDateTime 类型
LocalDate time = LocalDate.parse("2019/03/21", df);
int week = time.getDayOfWeek().getValue();
System.out.println(week);
}
}