◆◆◆◆◆一年中的第几周◆◆◆◆◆◆◆◆◆◆◆◆◆
//参数为当前时间
public static int backDayandWeek(String week) {
SimpleDateFormat sld = new SimpleDateFormat(“yyyy-MM-dd kk:mm:ss”);
Calendar calendar = Calendar.getInstance();Date ddate;
int weekOfYear = 0;
try {
//为空时默认为当前周
if ("".equals(week) || null == week) {} else {
ddate = sld.parse(week);
calendar.setTime(ddate);
}
calendar.set(calendar.DAY_OF_WEEK, calendar.FRIDAY);
//获取第几周
weekOfYear = calendar.get(calendar.WEEK_OF_YEAR);
return weekOfYear ;
}
◆◆◆◆◆◆◆得到指定日期的星期按中文显示方式 ◆◆◆◆◆◆◆
public static String backDayandWeek(String week) {
//week 为空时为当前日期
SimpleDateFormat sld = new SimpleDateFormat(“yyyy-MM-dd kk:mm:ss”);
Date date;
try {
Calendar c = Calendar.getInstance();
//为空时默认为当前时间的星期
if ("".equals(week) || null == week) {
} else {
date = sld.parse(week);
c.setTime(date);
}
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
"星期六" };
// 一周中的第几天(国外周日是第一天,所以需要减1)
int n = c.get(Calendar.DAY_OF_WEEK) - 1;
if (n < 0)
n = 0;
return weekDays[n];
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}