0
我想比較當前日期到數據庫中給定的日期只是我想用這個代碼來測試,但它始終顯示錯誤,如果當前的日期等於給定日期今天怎麼日期比較給定日期
<%
Date now = new Date();
DateFormat df =new SimpleDateFormat("dd/MM/yyyy");
String date= String.valueOf(df.format(now));
out.println(date);
if(date=="12/03/2014")
{
out.println("true");
}
else
{
out.println("false");
}
%>
這是我的真實代碼:其實我想檢查是否與當前日期一起離開日期匹配,然後從總工作日中減去請幫助我。怎麼辦?當您使用
<%
String mon=session.getAttribute("str1").toString();// mon,tue,... is given date in database
String tue=session.getAttribute("str2").toString();
String wed=session.getAttribute("str3").toString();
String thr=session.getAttribute("str4").toString();
String fri=session.getAttribute("str5").toString();
Date now =new Date();
DateFormat df =new SimpleDateFormat("dd/MM/yyyy");
String changedate= String.valueOf(df.format(now));
if(changedate== mon || changedate==tue || changedate==wed || changedate==thr || changedate==fri)
{
// "a" is total number of taken leave by employee like 1,2,3... days
String a=session.getAttribute("str16").toString();
int y=Integer.parseInt(a);
}
else{
// i am not getting any idea if employee did not take any leave then subtract 0 from total working day
}
%>
here display actual working day
<td><%= totalworkingday-y %>
謝謝,你能幫我實際的代碼 –