日期:2014-05-17 浏览次数:20707 次
public static void main(String[] args) {
final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
"星期六" };
String s = "2013-11-7";
SimpleDateFormat sdfInput = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
Date date = new Date();
try {
date = sdfInput.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
if (dayOfWeek < 0)
dayOfWeek = 0;
System.out.println(dayNames[dayOfWeek]);
}
select dayofweek(now());
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test {
public static void main(String[] args) {
final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
"星期六" };
String begin = "2013-11-01";
String end = "2013-11-10";
SimpleDateFormat sdfInput = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
Date dateb = new Date();
Date datee = new Date();
try {
dateb = sdfInput.parse(begin);
datee = sdfInput.parse(end);
} catch (ParseException e) {
e.printStackTrace();
}
long nowTime = dateb.getTime();
Date datenow = new Date();
datenow.setTime(nowTime);
Calendar calendar = Calendar.getInstance();
while(nowTime>=dateb.getTime()&&nowTime<=datee.getTime())
{ <