62,623
社区成员
发帖
与我相关
我的任务
分享
Calendar rightNow = Calendar.getInstance();
System.out.println(Calendar.MONDAY==rightNow.get(Calendar.DAY_OF_WEEK));
Date date = new Date();
System.out.println(date.getDay()==1?true:false);
public static boolean getDayOfWeek(Timestamp operTime,int day)
{
if(operTime!=null&&day>0&&day<=7)
{
Calendar c=Calendar.getInstance();
c.setTime(operTime);
return day==c.get(Calendar.DAY_OF_WEEK);
}
return false;
}
//判断输入的时间戳(Timestamp)是否所在周的星期几,其顺序为:星期天,一,二,三,四,五,六
public static Timestamp getDayOfWeek(Timestamp operTime,int day)
{
if(operTime!=null&&day>0&&day<=7)
{
Calendar c=Calendar.getInstance();
c.setTime(operTime);
return day==c.get(Calendar.DAY_OF_WEEK);
}
return false;
}
public class WeekDay
{
public static void main(String[] args){
String s="2007-11-19";
SimpleDateFormat formatYMD=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat formatE=new SimpleDateFormat("E");
Date d=null;
try{
d=formatYMD.parse(s);
}catch(ParseException ex){
ex.printStackTrace();
}
if((formatE.format(d)).equals("星期一")){
System.out.println(s+" 是星期一");
}
else
{
System.out.println(s+" 不是星期一");
}
}
}
java.util.Date nowDate = java.sql.Date.valueOf(这里写入日期) ;
java.text.SimpleDateFormat bartDateFormat = new java.text.SimpleDateFormat("EEE");
String week = bartDateFormat.format(nowDate).trim() ;
String newweek = "" ;
if(week.equals("星期一"))
{
就是周一了
}