package com;
import java.util.Calendar;
import java.util.Date;
public class Snippet {
public static String getWeekOfDate(Date dt) {
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
return weekDays[w];
}
public static void main(String[] args) {
String date=Snippet.getWeekOfDate(new Date());
System.out.println(date);
}
}
给定一个日期,判断星期几
最新推荐文章于 2020-12-21 00:27:10 发布