JSP基礎(chǔ) (獲取當(dāng)前時(shí)間) 第二十一天
下面的代碼用于顯示當(dāng)前時(shí)間,并根據(jù)當(dāng)前是幾點(diǎn)輸出相應(yīng)的提示信息,其中,使用java.util.Date thisday=new java.util.Date();語(yǔ)句來(lái)取得當(dāng)前時(shí)間,然后通過(guò)相應(yīng)的方法取得年,月,日,時(shí)和分的信息并輸出:
<% page contentType="text/html; charset=utf-8" import="java.util.*" %>
<body>
<%
//獲取當(dāng)前的時(shí)間
java.util.Date thisday = new java.util.Date();
%>
當(dāng)前時(shí)間:
<%=thisday.getYear()+1900%>年
<%=thisday.getMonth()+1%>月
<%=thisday.getDate()%>日
<%=thisday.getHours()%>時(shí)
<%=thisday.getMinutes()%>分
<%
String str = "歡迎訪問(wèn):"
int num = this.getHours();
switch(num){
case 8:
case 9:
case 10:
case 11:
{
out.print("歡迎你的訪問(wèn),上午好!");
break;
}
case 12:
{
out.print("中午好!");
break;
}
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
{
out.print("下午好!");
break;
}
</body>
<% page contentType="text/html; charset=utf-8" import="java.util.*" %>
<body>
<%
//獲取當(dāng)前的時(shí)間
java.util.Date thisday = new java.util.Date();
%>
當(dāng)前時(shí)間:
<%=thisday.getYear()+1900%>年
<%=thisday.getMonth()+1%>月
<%=thisday.getDate()%>日
<%=thisday.getHours()%>時(shí)
<%=thisday.getMinutes()%>分
<%
String str = "歡迎訪問(wèn):"
int num = this.getHours();
switch(num){
case 8:
case 9:
case 10:
case 11:
{
out.print("歡迎你的訪問(wèn),上午好!");
break;
}
case 12:
{
out.print("中午好!");
break;
}
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
{
out.print("下午好!");
break;
}
</body>
posted on 2008-08-21 04:23 程序手記 閱讀(1263) 評(píng)論(0) 編輯 收藏