我做了一个日历,想把当天那个日期的标签用特殊的边框显示出来。但是我不会那个判断语句,希望大家可以给我一个正确的判断语句。如果有其它的方法也可以
代码:其中week_log是星期几, month_day_score是这个月的总天数
for (int i = 7; i < 49; i++) { // 初始化标签
label[i].setText("");
}
week_log = week_log+6;
month_day_score = month_day_score+week_log;
for(j=1;j<=month_day_score;j++)
{
if(now.get(Calendar.DAY_OF_MONTH)==j) //就是这个地方的判断语句我不会,希望大家帮帮我,有其它方法也可以。
{
label[j].setBorder(new LineBorder(Color.blue,5));
}continue;
}
for (int i = week_log; i < month_day_score; i++, count++) {
label[i].setFont(font);
label[i].setText(count + "");
代码:其中week_log是星期几, month_day_score是这个月的总天数
for (int i = 7; i < 49; i++) { // 初始化标签
label[i].setText("");
}
week_log = week_log+6;
month_day_score = month_day_score+week_log;
for(j=1;j<=month_day_score;j++)
{
if(now.get(Calendar.DAY_OF_MONTH)==j) //就是这个地方的判断语句我不会,希望大家帮帮我,有其它方法也可以。
{
label[j].setBorder(new LineBorder(Color.blue,5));
}continue;
}
for (int i = week_log; i < month_day_score; i++, count++) {
label[i].setFont(font);
label[i].setText(count + "");
<%! String year;
String month;
String event;
String iyear;
String imonth;
String iday;
String msg;
String disday;
%>
<% month=request.getParameter("month");
year=request.getParameter("year");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>日</title>
<script Language="JavaScript">
<!--
function changeMonth()
{
var mm="calendar.jsp?month="+document.sm.month.value+"&year="+<%=year%>;
window.open(mm,"_self");
}
//--></script>
<script Language="JavaScript">
<!--
function changeYear()
{
var mm="calendar.jsp?month="+<%=month%>+"&year="+document.sm.year.value;
window.open(mm,"_self");
}
//--></script>
<style> </style>
</head>
<%!String days[];%>
<%
days = new String[42];
for (int i = 0; i < 42; i++) {
days[i] = "";
}
%>
<%
Calendar thisMonth = Calendar.getInstance();
if (month != null && (!month.equals("null")))
thisMonth.set(Calendar.MONTH, Integer.parseInt(month));
if (year != null && (!year.equals("null")))
thisMonth.set(Calendar.YEAR, Integer.parseInt(year));
year = String.valueOf(thisMonth.get(Calendar.YEAR));
month = String.valueOf(thisMonth.get(Calendar.MONTH));
disday = String.valueOf(thisMonth.get(Calendar.DAY_OF_MONTH));
thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);
thisMonth.set(Calendar.DAY_OF_MONTH, 1);
int firstIndex = thisMonth.get(Calendar.DAY_OF_WEEK) - 1;
int maxIndex = thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < maxIndex; i++) {
days[firstIndex + i] = String.valueOf(i + 1);
}
%>
<body> <FORM name="sm" method="post" action="calendar.jsp">
<table border="0" cellspacing="0" cellpadding="0" width="176"
height="23" bgcolor="#F88936">
<tr>
<td align="center"
style="font-size:16px;color:#FFFFFF;font-weight:bold">
<%=year%>
年
<%=Integer.parseInt(month) + 1%>
月
</td>
</tr>
</table>
<table border="0" cellspacing="1" cellpadding="0" width="176"
height="81" bgcolor="#F88936"> <div align=center>
<tr style="font-size:14px;color:red">
<th width="25" height="20" bgcolor="#F1F1F1">
日
</th>
<th width="25" height="20" bgcolor="#F1F1F1" style="color:#000000">
一
</th>
<th width="25" height="20" bgcolor="#F1F1F1" style="color:#000000">
二
</th>
<th width="25" height="20" bgcolor="#F1F1F1" style="color:#000000">
三
</th>
<th width="25" height="20" bgcolor="#F1F1F1" style="color:#000000">
四
</th>
<th width="25" height="20" bgcolor="#F1F1F1" style="color:#000000">
五
</th>
<th width="25" height="20" bgcolor="#F1F1F1">
<font color="red">六</font>
</th>
</tr>
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@192.168.10.102:1521:orcl"; String user = "bjmy"; String password = "bjmy"; Connection conn = DriverManager.getConnection(url, user, password); Statement stmt = conn
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = null;
%> <%
for (int j = 0; j < 6; j++) {
%>
<tr style="font-family:arial;">
<%
for (int i = j * 7; i < (j + 1) * 7; i++) {
%>
<%
Calendar cal = Calendar.getInstance();
if (days[i].toString().equals(
String.valueOf(cal.get(Calendar.DATE)))
&& Integer.parseInt(month) + 1 == cal
.get(Calendar.MONTH) + 1
&& Integer.parseInt(year) == cal
.get(Calendar.YEAR)) {
%>
<td width="12%" height="14" bgcolor="#3D95FF" valign="middle"
align="center">
<%
} else {
%>
<td width="12%" height="14" bgcolor="#FFFFFF" valign="middle"
align="center">
<%
}
%>
<a href="#"
onClick="javascript:window.open('jump.jsp?year=<%=year%>&month=<%=Integer.parseInt(month) + 1%>&date=<%=days[i]%>','','width=450,height=400,toolbar=no, status=no, menubar=no, resizable=no, scrollbars=yes');return false;"
target="main" title="<%=rs.getString("event")%>"> <font
size="2"><%=days[i]%>
</font>
</a>
</td>
<%
} else {
%> <%
Calendar cal = Calendar.getInstance();
if (days[i].toString().equals(
String.valueOf(cal.get(Calendar.DATE)))
&& Integer.parseInt(month) + 1 == cal
.get(Calendar.MONTH) + 1
&& Integer.parseInt(year) == cal
.get(Calendar.YEAR)) {
%>
<td width="12%" height="14" bgcolor="#3D95FF" valign="middle"
align="center">
<%
} else {
%>
<td width="12%" height="14" bgcolor="#FFFFFF" valign="middle"
align="center">
<%
}
%>
<font size="2"><%=days[i]%>
</font></a>
</td>
<%
}
%>
<%
}
%>
</tr>
<%
}
conn.close();
stmt.close();
rs.close();
%> </div>
</table>
<table border="0" width="176" height="20">
<tr>
<td align="left" width=28% style="font-family:arial;">
<input type=text name="year" value=<%=year%> size=4 maxlength=4>
</td>
<td>
年
</td>
<td width=30%>
<select name="month" size="1" onchange="changeMonth()">
<option value="0">
1月
</option>
<option value="1">
2月
</option>
<option value="2">
3月
</option>
<option value="3">
4月
</option>
<option value="4">
5月
</option>
<option value="5">
6月
</option>
<option value="6">
7月
</option>
<option value="7">
8月
</option>
<option value="8">
9月
</option>
<option value="9">
10月
</option>
<option value="10">
11月
</option>
<option value="11">
12月
</option>
</select>
</td> <td width=28%>
<input type=submit value="提交">
</td>
</tr>
</table>
</FORM> <script Language="JavaScript">
<!--
document.sm.month.options.selectedIndex=<%=month%>;
//-->
</script> </body></html>
这是个jsp页面,直接能用,效果是http://211.103.154.75:8080/Calender/calendar.jsp
自己看吧
String str = "2008-11-20";//这是你程序中定义的时间
SimpleDateFormat dateFormat = new SimpleDateFormat("yyy-MM-dd");
Date date1 = dateFormat.parse(str);
Date date = new Date();//这是系统当前时间
if (date.compareTo(date1) == 1){
System.out.println();
}
if (date.compareTo(date1) == -1){
System.out.println();
}
if (date.compareTo(date1) == 0){//当返回0时,代表今天和预期的时间相同,然后做你想做的事情
System.out.println();
}
if (i == currentDay)
//显示蓝色字体
else
//显示红色字体
}