public class Main{
public static void main(String [] args) throws Throwable {
String a = dayForWeek("2019-1-6");
System.out.println("是"+a);
}
public static String dayForWeek(String pTime) throws Throwable {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date tmpDate = format.parse(pTime);
Calendar cal = Calendar.getInstance();
String[] weekDays = { "星期天", "星期一", "星期二", "星期三天", "星期四", "星期五", "星期六" };
try {
cal.setTime(tmpDate);
} catch (Exception e) {
e.printStackTrace();
}
int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
System.out.println("是一年的第"+cal.get(Calendar.DAY_OF_YEAR)+"天");
System.out.println("是1年的第"+cal.get(Calendar.WEEK_OF_YEAR)+"周");
if (w < 0)
w = 0;
return weekDays[w];
}
}
运行结果:
是一年的第6天
是1年的第2周
是星期天
计算某一日期时是星期几 一年的第几天 第几周
最新推荐文章于 2022-06-01 23:48:43 发布