Java程序:输入某年某月某日,判断该天星期几,是这一年的第几天.
2个回答
展开全部
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.Date;
public class DateTest {
public static void main(String[] args) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String dateStr;
try {
System.out.println("请按照2012-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.YEAR) + "年的第"
+ calendar.get(Calendar.DAY_OF_YEAR) + "天");
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.Date;
public class DateTest {
public static void main(String[] args) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String dateStr;
try {
System.out.println("请按照2012-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.YEAR) + "年的第"
+ calendar.get(Calendar.DAY_OF_YEAR) + "天");
} catch (Exception e) {
e.printStackTrace();
}
}
}
追问
好像有点问题,运行之后达不到效果,请您在看下吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询