输入某年某月某日,判断这一天是这一年的第几周,第几天,星期几?
package demo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.Date;
/**
* Created by asus on 2017/2/8.
*/
public class Data {
public static void main(String[] args) {
/* Scanner in = new Scanner(System.in);// 调用键盘输入API
System.out.println("请输入内容");//显示 “请输入内容”
String answer =in.nextLine();//定义String 类型的变量answer接住用户输入的字符串
System.out.println(answer);*/
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String dateStr;
try {
System.out.println("请按照2017-1-1格式输入日期:");
dateStr = br.readLine();
Calendar calendar = Calendar.getInstance();
java.text.SimpleDateFormat formt = new java.text.SimpleDateFormat(
"yyyy-MM-dd");
Date date = formt.parse(dateStr);
calendar.setTime(date);
System.out.println("今天星期" + (calendar.get(Calendar.DAY_OF_WEEK )-1));
System.out.println("是这一年中的第: " + calendar.get(Calendar.WEEK_OF_YEAR)+"个星期");
System.out.println("今天是" + calendar.get(Calendar.YEAR) + "年的第"
+ calendar.get(Calendar.DAY_OF_YEAR) + "天");
} catch (Exception e) {
e.printStackTrace();
}
}
}