判断周六、周日的奇怪现象,附源码
我这段代码是要返回是否是周六、周日的代码,运行没有问题,但是判断的不对呢,4月1日命名是周日,但是返回来的值是周一!!为什么呢!!
package compara_time;
import java.text.*;
import java.util.Date;
import java.util.Calendar;
//import java.util.Set;
/**
* <p> Title: </p>
* <p> Description: </p>
* <p> Copyright: Copyright (c) 2007 </p>
* <p> Company: </p>
* @author not attributable
* @version 1.0
*/
public class Compara_Time {
private String v_btime;
private String v_etime;
public Compara_Time() {
}
public void setTime(String a,String b){//初始化时间
v_btime=a;
v_etime=b;
}
public String Compara_Result(String begin,String end) throws Exception{
String result= "0 ";
SimpleDateFormat bartDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss ");
String beginTime=begin; //指定一个字符串
String endTime=end; //指定一个字符串
String begin_work= " ";
String end_work= " ";
int day=0;
int day1=0;
//取日期是否是周末
Calendar ca = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat( "yyyy-mm-dd ");
try{
System.out.print(beginTime+ "beginTime ");
if ( beginTime.equals( " ") || beginTime==null){
result = "00 ";
}
else{
Date dt1= df.parse(beginTime);
ca.setTime(dt1);
day = ca.get(ca.DAY_OF_WEEK);
System.out.print(day+ "day ");
if(day == ca.SUNDAY || day == ca.SATURDAY){ //周六周日
result = "100 ";
}
else{
begin_work = beginTime.substring(0, 11) + v_btime;// "8:40:00 ";//时间在8:40前
if (bartDateFormat.parse(begin_work).getTime() > =
bartDateFormat.parse(beginTime).getTime()) {