用 GregorianCalendar 即可.import java.util.*; public class T { public static void main(String[] args) throws Exception { GregorianCalendar cale = new GregorianCalendar(2006,2,12); int day = cale.get(Calendar.DAY_OF_WEEK); int result = -1;
switch(day) { case 1: case 2: case 7: result = 5; break; case 3: result = 1; break; case 4: result = 2; break; case 5: result = 3; break; case 6: result = 4; break; }
public class T
{
public static void main(String[] args) throws Exception
{
GregorianCalendar cale = new GregorianCalendar(2006,2,12);
int day = cale.get(Calendar.DAY_OF_WEEK);
int result = -1;
switch(day)
{
case 1:
case 2:
case 7: result = 5; break;
case 3: result = 1; break;
case 4: result = 2; break;
case 5: result = 3; break;
case 6: result = 4; break;
}
System.out.println("2006-2-12之前最近的工作日是:星期"+result);
}
}
import java.io.IOException;
import java.text.SimpleDateFormat;public class FindWorkDate
{
public FindWorkDate( )
{
super();
// TODO 自动生成构造函数存根
}
public static Date findDate(Date date){
int i=0;
Date oDate = date ;
int day ;
day = oDate.getDay() ;
if(day == 0 ) i =2;
if(day == 1 ) i =3;
if(day>1) i=1;
oDate.setDate(date.getDate() -i );
return oDate;
} /**
* @param args
* @throws IOException
*/
public static void main( String[] args ) throws IOException
{
// TODO 自动生成方法存根
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.print( sdf.format(FindWorkDate.findDate(new Date())));
}}