eclipse从键盘输入一个日期,显示该日期是星期几。求大神给个完整的代码啊。。

2025-03-24 06:44:59
推荐回答(3个)
回答1:

/**
* 判断当前日期是星期几
*
* @param pTime 修要判断的时间
* @return dayForWeek 判断结果
* @Exception 发生异常
*/
public static int dayForWeek(String pTime) throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(format.parse(pTime));
int dayForWeek = 0;
if(c.get(Calendar.DAY_OF_WEEK) == 1){
dayForWeek = 7;
}else{
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
}
return dayForWeek;
}

回答2:

Scanner input = new Scanner(System.in);
input.next();

回答3:

有问我的时间,不如自己看手机[摊手]