posts - 48,  comments - 5,  trackbacks - 0
  计算生日属相生肖事例

1、 输入页面文件代码:inputDateTime.jsp

2、 计算(生日-属相-生肖)文件代码:compute.jsp

3、 错误提示文件代码:error_inputDateTime.jsp

4、 北京奥运倒计时文件代码:beijingaoyun29.html

5、 日期时间脚本显示文件代码:time.htm

6、 InputDateTimeForm.java

7、 InputDateTimeAction.java

8、 计算 生日 java类:Shengri.java

9、 计算 属相 java类:Shengxiao.java

10、计算 星座 java类:Xingzuo.java
----------------  1
、输入页面文件代码inputDateTime.jsp ------------------------------

<%@ page language="java" pageEncoding="gbk"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

 

<html>

    <head>

        <title>请输入您的出生日期</title>

           

        <style type="text/css">

<!--

body {

    background-attachment: fixed;

    background-image: url(../image/xiaoxiang.jpg);

    background-repeat: repeat-x;

}

-->

        </style>

    </head>

    <body>

    <center><p><br><p><br><p><br><p><br><p><br><p><br>

<jsp:include flush="true" page="/datetime/beijingaoyun29.html"></jsp:include>

    请输入您的出生日期

        <html:form action="/inputDateTime">

            <html:text property="year" size="8" maxlength="5"/><html:errors property="year"/>

            <html:text property="month" size="8" maxlength="2"/><html:errors property="month"/>

            <html:text property="day" size="8" maxlength="2"/><html:errors property="day"/><br/>

            <html:text property="hours" size="8" maxlength="2"/><html:errors property="hours"/>

            <html:text property="minute" size="8" maxlength="2"/><html:errors property="minute"/>

            <html:text property="second" size="8" maxlength="2"/><html:errors property="second"/><p>                     

            <html:submit value="[看看效果]"/>

        </html:form>

<jsp:include flush="true" page="/datetime/error_inputDateTime.jsp"></jsp:include>        

    </center>

    </body>

</html>

------------ 2、计算(生日-属相-生肖)文件代码:compute.jsp  -------------------------

<%@ page language="java" pageEncoding="gbk"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

 

<html>

    <head>

        <title>计算页面</title>

       

<style type="text/css">

<!--

body {

    background-imageurl(image/xiaoxiang.jpg);

    background-attachment: fixed;

    background-repeat: repeat-x;

}

-->

</style>       

    </head>

<%

    String year=request.getParameter("year");

    String month=request.getParameter("month");

    String day=request.getParameter("day");

    String hours=request.getParameter("hours");

    String minute=request.getParameter("minute");

    String second=request.getParameter("second");

 %>

 

<!------------------------------------------------------------------>

<!--               计算您属相的代码                              -->

<!------------------------------------------------------------------>

<%       

        int toyear=1984;

        String birthyear1=year;    

        int birthyear=Integer.parseInt(birthyear1);

        String birthpet="";

        int x=(toyear-birthyear)%12;

       

        if(Integer.toString(birthyear)!=null){

       

        if((x == 0)){

            birthpet="您属鼠" ;    

        }

        else{

             if((x == 1)||(x == -11)){

                 birthpet="您属牛" ;        

             }

             else{

                  if((x == 2) || (x == -10)){

                      birthpet="您属虎" ;       

                  }

                  else{

                       if((x == 3)||(x == -9)){

                           birthpet="您属兔";        

                       }

                       else{

                            if((x == 4)||(x == -8)){

                                birthpet="您属龙";        

                            }

                            else{

                                 if((x == 5)||(x == -7)){

                                     birthpet="您属蛇";  

                                 }

                                 else{

                                     if((x == 6)||(x == -6)){

                                         birthpet="您属马";     

                                     }

                                     else{

                                         if((x == 7)||(x == -5)){

                                             birthpet="您属羊";     

                                         }

                                         else{

                                             if((x == 8)||(x == -4)){

                                                 birthpet="您属猴";    

                                             }

                                             else{

                                                 if((x == 9)||(x == -3)){

                                                     birthpet="您属鸡";   

                                                 }

                                                 else{

                                                     if((x == 10)||(x == -2)){

                                                         birthpet="您属狗";       

                                                     }

                                                     else{

                                                         if((x == 11)||(x == -1)){

                                                             birthpet="您属猪";        

                                                         }

                                                     }

                                                }

                                            }

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

             }           

        }else{

            birthpet="请输入你的出生年份";

    }

%>

<!------------------------------------------------------------------>

<!------------------------------------------------------------------>

<!--               计算您星座的代码                              -->

<!------------------------------------------------------------------>

<%

    String xingzuo;

    int xmonth=Integer.parseInt(month);

    int xday=Integer.parseInt(day);

   

        if( (1==xmonth && xday>=21 && xday<=31) || (2==xmonth && 1<=xday&&xday<=18) ){

            xingzuo="水瓶座";

        }

        elseif( (2==xmonth && xday>=19 && xday<=29) || (3==xmonth && 1<=xday&&xday<=20) ){

            xingzuo="双鱼座";

        }

        elseif( (3==xmonth && xday>=21 && xday<=31) || (4==xmonth && 1<=xday&&xday<=20) ){

            xingzuo="白羊座";

        }

        elseif( (4==xmonth && xday>=21 && xday<=30) || (5==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="金牛座";

        }

        elseif( (5==xmonth && xday>=22 && xday<=31) || (6==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="双子座";

        }

        elseif( (6==xmonth && xday>=22 && xday<=30) || (7==xmonth && 1<=xday&&xday<=22) ){

            xingzuo="巨蟹座";

        }

        elseif( (7==xmonth && xday>=23 && xday<=31) || (8==xmonth && 1<=xday&&xday<=23) ){

            xingzuo="狮子座";

        }

        elseif( (8==xmonth && xday>=24 && xday<=31) || (9==xmonth && 1<=xday&&xday<=22) ){

            xingzuo="处女座";

        }

        elseif( (9==xmonth && xday>=23 && xday<=30) || (10==xmonth && 1<=xday&&xday<=23) ){

            xingzuo="天秤座";

        }

        elseif( (10==xmonth && xday>=24 && xday<=31) || (11==xmonth && 1<=xday&&xday<=22) ){

            xingzuo="天蝎座";

        }

        elseif( (11==xmonth && xday>=23 && xday<=30) || (12==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="射手座";

        }

        elseif( (12==xmonth && xday>=22 && xday<=31) || (1==xmonth && 1<=xday&&xday<=20) ){

            xingzuo="摩羯座";

        }

        else{

            xingzuo="日期错误!";

        }

 %>

<body OnLoad="startclock()">

<center>

<p><br><p><br><p><br><p><br><p><br><p><br>

 <!-------------------- 接收您的出生日期 ---------------->       

   <form name="chushengri">

       您的出生日期:

      <textarea name="year0" cols="12" rows="1" readonly ><%= year %></textarea>年 

      <textarea name="month0" cols="12" rows="1" readonly ><%= month %></textarea>

      <textarea name="day0" cols="12" rows="1" readonly ><%= day %></textarea><br>

      您的出生时间:

      <textarea name="hours0" cols="12" rows="1" readonly ><%= hours %></textarea>

      <textarea name="minute0" cols="12" rows="1" readonly ><%= minute %></textarea>

      <textarea name="second0" cols="12" rows="1" readonly ><%= second %></textarea><p>

      您的属相:<textarea name="shuxiang" cols="12" rows="1" readonly ><%= birthpet %></textarea>

      您的星座:<textarea name="xingzuo" cols="12" rows="1" readonly ><%= xingzuo %></textarea>     

   </form>

   

   

       

<!----------------------------------------------------------------->

<!--               以下是用于计算的脚本代码                        -->

<!----------------------------------------------------------------->   

<script type="text/javascript">

<!-- Begin

/*--------------------获取出生日期------------------------**/

var byear = document.chushengri.year0.value;

var mm = document.chushengri.month0.value;

var bday = document.chushengri.day0.value;

var bhours = document.chushengri.hours0.value;

var bminute = document.chushengri.minute0.value;

var bsecond = document.chushengri.second0.value;

/**-------------------------------------------------------*/

var year = new Date();

var year2 = year.getYear();

var year3 = (year < 2000) ? year2 + 1900 : year2;

//-----------计算出岁数----------------------------------

thedate = new Date();

yy2 = thedate.getYear();

mm2 = thedate.getMonth() + 1;

dd2 = thedate.getDate();

if (yy2 < 100) yy2 += 1900

var yourage = yy2 - byear;

if (mm2 < mm) yourage--;

if ((mm2 == mm) && (dd2 < bday)) yourage--;

//-------------------------------------------------------

TMonth = new Array(

'January','February','March',

'April','May','June','July',

'August','September','October',

'November','December'

);

CurMonth = mm - 1;

var bmonth = TMonth[CurMonth];

var age2 = yourage + 1;//岁数加1,下一年几岁

var timerID;

var timerRunning = false;

var today = new Date();

var startday = new Date();

var enday = new Date();

var secPerDay = 0;

var minPerDay = 0;

var hourPerDay = 0;

var secsLeft = 0;

var secsRound = 0;

var secsRemain = 0;

var minLeft = 0;

var minRound = 0;

var minRemain = 0;

var timeRemain = 0;

/*-------------------------------------------------------------------------------------------------*/

function stopclock() {

if(timerRunning)

clearTimeout(timerID);

timerRunning = false;

}

/*---------------------页面初始化跳用 函数-----------------------------------------------------------*/

function startclock() {

stopclock();

showtime();

showtime1();

}

/*--------------------------------------------------------------------------------------------------*/

//--------------------计算下一岁生日的倒计时 函数---------------------------------------------------------

function showtime() {

today = new Date();//创建当前时期变量

enday = new Date(""+bmonth+", "+bday+" "+year3+" 00:00");//获取出生日期

enday.setYear(""+year3+"");

enday.setMonth(mm-1);

enday.setDate(bday);

enday.setHours(bhours);

enday.setMinutes(bminute);

enday.setSeconds(bsecond);

secsPerDay = 1000 ; //毫秒

minPerDay = 60 * 1000 ;//一分钟有多少毫秒

hoursPerDay = 60 * 60 * 1000;//一小时有多少毫秒

PerDay = 24 * 60 * 60 * 1000;//一天有多少毫秒

//-----------计算出离下一岁生日的 秒数------------------------------------------------------------------

secsLeft = (enday.getTime() - today.getTime()) / minPerDay;

secsRound = Math.round(secsLeft);

secsRemain = secsLeft - secsRound;

secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;

secsRemain = Math.round(secsRemain);

//------------------------------------------------------------------------------------------------------

//-----------计算出离下一岁生日的 分钟数-----------------------------------------------------------------

minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay);

minRound = Math.round(minLeft);

minRemain = minLeft - minRound;

minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain =((minLeft - minRound) * 60);

minRemain = Math.round(minRemain - 0.495);

//------------------------------------------------------------------------------------------------------

//-----------计算出离下一岁生日的 小时数-----------------------------------------------------------------

hoursLeft = ((enday.getTime() - today.getTime()) / PerDay);

hoursRound = Math.round(hoursLeft);

hoursRemain = hoursLeft - hoursRound;

hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24) :hoursRemain = ((hoursLeft - hoursRound) * 24);

hoursRemain = Math.round(hoursRemain - 0.5);

//------------------------------------------------------------------------------------------------------

//-----------计算出离下一岁生日的 天数-------------------------------------------------------------------

daysLeft = ((enday.getTime() - today.getTime()) / PerDay);

daysLeft = (daysLeft - 0.5);

daysRound = Math.round(daysLeft);

daysRemain = daysRound;

//------------------------------------------------------------------------------------------------------

if (daysRemain == 1) day_rem = " 天 "

else day_rem = " 天 "

if (hoursRemain == 1) hour_rem = " 小时 "

else hour_rem = " 小时 "

if (minRemain == 1) min_rem = " 分钟 "

else min_rem = " 分钟 "

if (secsRemain == 1) sec_rem = " 秒"

else sec_rem = " 秒"

//---------完整的显示语句---------------------------------------------------------------------------------

timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem;

document.down.face.value = timeRemain;//给文本框传递数值

timerID = setTimeout("showtime()",1000);

timerRunning = true;

if (daysRemain < 0) year3 = year3 + 1

}

//--------------------计算出你在世上的存活时间的计时 函数------------------------------------------------------

function showtime1() {

startday = new Date(""+bmonth+" "+bday+", "+byear+" 00:00 EDT");

startday.setYear(""+byear+"");

//startday.setMonth(mm);

//startday.setDate(bday);

startday.setHours(bhours);

startday.setMinutes(bminute);

startday.setSeconds(bsecond);

today = new Date();

secsPerDay = 1000 ;//毫秒

minPerDay = 60 * 1000 ;//一分钟有多少毫秒

hoursPerDay = 60 * 60 * 1000;//一小时有多少毫秒

PerDay = 24 * 60 * 60 * 1000;//一天有多少毫秒

//-----------计算出你在世上存活的 秒数------------------------------------------------------------------

secsLeft = (today.getTime() - startday.getTime()) / minPerDay;

secsRound = Math.round(secsLeft);

secsRemain = secsLeft - secsRound;

secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain =(secsLeft - secsRound) * 60;

secsRemain = Math.round(secsRemain);

//-----------计算出你在世上存活的 分钟数------------------------------------------------------------------

minLeft = ((today.getTime() - startday.getTime()) / hoursPerDay);

minRound = Math.round(minLeft);

minRemain = minLeft - minRound;

minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain =((minLeft - minRound) * 60);

minRemain = Math.round(minRemain - 0.495);

//-----------计算出你在世上存活的 小时数------------------------------------------------------------------

hoursLeft = ((today.getTime() - startday.getTime()) / PerDay);

hoursRound = Math.round(hoursLeft);

hoursRemain = hoursLeft - hoursRound;

hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24);

hoursRemain = Math.round(hoursRemain - 0.5);

//-----------计算出你在世上存活的 天数------------------------------------------------------------------

daysLeft = ((today.getTime() - startday.getTime()) / PerDay);

daysLeft = (daysLeft - 0.5);

daysRound = Math.round(daysLeft);

daysRemain = daysRound;

if (daysRemain == 1) day_rem = " 天 "

else day_rem = " 天 "

if (hoursRemain == 1) hour_rem = " 小时 "

else hour_rem = " 小时 "

if (minRemain == 1) min_rem = " 分钟 "

else min_rem = " 分钟 "

if (secsRemain == 1) sec_rem = " 秒"

else sec_rem = " 秒"

//---------完整的显示语句---------------------------------------------------------------------------------

timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain +sec_rem;

document.up.face.value = timeRemain;//给文本框传递数值

timerID = setTimeout("showtime1()",1000);

timerRunning = true;

}

// End -->

</script>  

<!----------------------------------------------------------------->

<!--               用于计算的脚本代码结束                          -->

<!----------------------------------------------------------------->   

<!--------------------- 显示计算结果 ------------------------------------------------------------------>

<form name="down" onSubmit="0">

<script Language="JavaScript">

document.write("今年你已经 "+yourage+" 岁了, 你离 "+age2+" 岁还有:");

</script>

<br>

<input type="text" name="face" size="47" value="您下一岁生日的倒计时">

</form>

<p>

<br>

<form name="up" onSubmit="1">

以下是您在这世上存活的时间<br>

<input type="text" name="face" size="47" value="您在这世上存活的时间">

</form>

<!----------------------------------------------------------------------------------------------------->       

<html:link page="/datetime/inputDateTime.jsp">返回上一页</html:link>

</center>      

</body>

</html>

----------------- 北京奥运倒计时文件代码:beijingaoyun29.html -----------------------

<html>

 <head>

    <title>北京奥运倒计时</title>

 </head>

 

<body OnLoad="startclock()">

<center>   

<!----------------------------------------------------------------->

<!--               以下是用于计算的脚本代码                        -->

<!----------------------------------------------------------------->   

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

/*****           获取 北京 第29届 奥运会 开幕日期                   *****/

/*****     2008年8月8日晚上8点8分 戊子年七月初八星期五           *****/   

var byear = 2008 ;

var mm = 8 ;

var bday = 8 ;

/******************************************************************/

TMonth = new Array(

'January','February','March',

'April','May','June','July',

'August','September','October',

'November','December'

);

CurMonth = mm - 1;

var bmonth = TMonth[CurMonth];

var year = new Date();

var year2 = year.getYear();

var year3 = (year < 2000) ? year2 + 1900 : year2;

var timerID;

var timerRunning = false;

var today = new Date();

var startday = new Date();

var enday = new Date();

var secPerDay = 0;

var minPerDay = 0;

var hourPerDay = 0;

var secsLeft = 0;

var secsRound = 0;

var secsRemain = 0;

var minLeft = 0;

var minRound = 0;

var minRemain = 0;

var timeRemain = 0;

/*-------------------------------------------------------------------------------------------------*/

function stopclock() {

if(timerRunning)

clearTimeout(timerID);

timerRunning = false;

}

/*---------------------页面初始化跳用 函数-----------------------------------------------------------*/

function startclock() {

stopclock();

showtime();

}

/*--------------------------------------------------------------------------------------------------*/

//--------------------计算 2008年8月8日晚上8点8分 北京 第29届 奥运会的倒计时 函数------------------------

function showtime() {

today = new Date();//创建当前时期变量

enday = new Date(""+bmonth+", "+bday+" "+year3+" 00:00");//获取 第29届 奥运会 日期

enday.setYear(""+year3+"");

enday.setHours(20);

enday.setMinutes(8);

startday.setYear(""+byear+"");

secsPerDay = 1000 ; //毫秒

minPerDay = 60 * 1000 ;//一分钟有多少毫秒

hoursPerDay = 60 * 60 * 1000;//一小时有多少毫秒

PerDay = 24 * 60 * 60 * 1000;//一天有多少毫秒

//-----------计算出 秒数------------------------------------------------------------------

secsLeft = (enday.getTime() - today.getTime()) / minPerDay;

secsRound = Math.round(secsLeft);

secsRemain = secsLeft - secsRound;

secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;

secsRemain = Math.round(secsRemain);

//------------------------------------------------------------------------------------------------------

//-----------计算出 分钟数-----------------------------------------------------------------

minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay);

minRound = Math.round(minLeft);

minRemain = minLeft - minRound;

minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain =((minLeft - minRound) * 60);

minRemain = Math.round(minRemain - 0.495);

//------------------------------------------------------------------------------------------------------

//-----------计算出 小时数-----------------------------------------------------------------

hoursLeft = ((enday.getTime() - today.getTime()) / PerDay);

hoursRound = Math.round(hoursLeft);

hoursRemain = hoursLeft - hoursRound;

hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft)  * 24) :hoursRemain = ((hoursLeft - hoursRound) * 24);

hoursRemain = Math.round(hoursRemain - 0.5);

//------------------------------------------------------------------------------------------------------

//-----------计算出 天数------------------------------------------------------------------

daysLeft = (( startday.getTime() - today.getTime() ) / PerDay);

daysLeft = (daysLeft - 0.5);

daysRound = Math.round(daysLeft);

daysRemain = daysRound;

if (daysRemain == 1) day_rem = " 天 "

else day_rem = " 天 "

if (hoursRemain == 1) hour_rem = " 小时 "

else hour_rem = " 小时 "

if (minRemain == 1) min_rem = " 分钟 "

else min_rem = " 分钟 "

if (secsRemain == 1) sec_rem = " 秒"

else sec_rem = " 秒"

//---------完整的显示语句---------------------------------------------------------------------------------

timeRemain = " "+daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem;

document.down.face.value = timeRemain;//给文本框传递数值

timerID = setTimeout("showtime()",1000);

timerRunning = true;

if (daysRemain < 0) year3 = year3 + 1

}

// End -->

</script>  

<!----------------------------------------------------------------->

<!--               用于计算的脚本代码结束                          -->

<!----------------------------------------------------------------->

<!--------------------- 显示计算结果 ------------------------------------------------------------------>

<form name="down" onSubmit="0">

北京奥运倒计时:<input type="text" name="face" size="32" value="北京奥运倒计时">

</form>

<!-- 第三种形式 -->

<div id="clock" ></div>

<SCRIPT language=Javascript1.2>

<!--

function show() {

 if(!document.layers && !document.all) return;

 var d = new Date();

 var iYear = d.getYear()

 var iMonth = d.getMonth()

 var iDay = d.getDate()

 var sWeek = d.getDay()

 var sHour = d.getHours()

 var sMinute = d.getMinutes()

 var sSecond = d.getSeconds()

 if(sWeek == 0) sWeek = "<font color=#ffffff>星期天</font>";

 if(sWeek == 1) sWeek = "星期一";

 if(sWeek == 2) sWeek = "星期二";

 if(sWeek == 3) sWeek = "星期三";

 if(sWeek == 4) sWeek = "星期四";

 if(sWeek == 5) sWeek = "星期五";

 if(sWeek == 6) sWeek = "<font color=#ffffff>星期六</font>";

 if(sHour <= 9) sHour = "0" + sHour;

 if(sMinute <= 9) sMinute = "0" + sMinute;

 if(sSecond <= 9) sSecond = "0" + sSecond;

 sClock = "现在时间:" + iYear + "年" + (iMonth + 1) + "月" + iDay + "日 " + sWeek

    + " " + sHour + ":" + sMinute + ":" + sSecond;

 if(document.layers) {

    document.layers.clock.document.write(sClock);

    document.layers.clock.document.close();

 }

 else if(document.all)

    clock.innerHTML = sClock;

 setTimeout("show()", 1000);

}

show();

//-->

</SCRIPT>

<p><hr>

</center>

 </body>

</html>

----------------- 错误提示文件代码:error_inputDateTime.jsp ------------------------

<%@ page language="java" pageEncoding="GBK"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html lang="true">

 <head>

    <html:base />

   

    <title>显示不合法输入提示</title>

         

    <meta http-equiv="pragma" content="no-cache">

    <meta http-equiv="cache-control" content="no-cache">

    <meta http-equiv="expires" content="0">   

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

    <meta http-equiv="description" content="This is my page">

    <!--

    <link rel="stylesheet" type="text/css" href="styles.css">

    -->

 </head>

 

 <body>

 <FONT color=#ff0033>

         

        <logic:present name="error_inputDateTime" scope="request">

           <bean:write name="error_inputDateTime"/>

        </logic:present>

 </FONT>

 </body>

</html:html>

------------------- 日期时间脚本显示文件代码:time.htm -----------------------

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>日期时间脚本显示</title>

</head>

<body bgcolor="#AED5E8"><center>

日期时间脚本显示<p><hr>

<!-- 第一种形式 -->

<div align="center">

<SCRIPT language=JavaScript>

<!--

var noon;

var time=new Date();

var hour=time.getHours();

var minute=time.getMinutes();

var today=new Date;

var week=new Array(7);

week[0]="天";

week[1]="一";

week[2]="二";

week[3]="三";

week[4]="四";

week[5]="五";

week[6]="六";

if (hour<5) noon="凌晨";

if (hour>4 & hour<8) noon="早晨";

if (hour>7 & hour<12) noon="上午";

if (hour==12) noon="中午";

if (hour>12 & hour<19) noon="下午";

if (hour>18 & hour<23) noon="晚上";

if (hour>22) noon="深夜";

if (hour>12) hour=hour-12;

if (hour<10) hour="0"+hour;

if (minute<10) minute="0"+minute;

document.write("<span class='p9'>");

document.write(today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 星期"+week[today.getDay()]+" "+"北京时间:"+noon+" "+hour+":"+minute+" ");

document.write("</span>");

//-->

</SCRIPT>

</div>

<p><hr>

<!-- 第二种形式 -->

<FONT color=#f8941f>        

<SCRIPT language=JavaScript>

<!--                                                                            

// Begin                                                                            

   document.write("今天是:")

   var enable=0; today=new Date();                                                                            

   var day; var date;                                                                             

   var time_start = new Date();                                                                            

   var clock_start = time_start.getTime();                                                                             

   if(today.getDay()==0) day="星期日"                                                                            

   if(today.getDay()==1) day="星期一"                                                                             

   if(today.getDay()==2) day="星期二"                                                                            

   if(today.getDay()==3) day="星期三"                                                                            

   if(today.getDay()==4) day="星期四"                                                                            

   if(today.getDay()==5) day="星期五"                                                                            

   if(today.getDay()==6) day="星期六"                                                                             

   date=(today.getYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 ";                                                                            

   document.write(date+day);                                                                             

// -->

</SCRIPT><br>

<SCRIPT language=JavaScript>

<!--

var mess1="你正在登陆的是:逍湘个人网!";

var mess2= "你正在登陆的是:逍湘个人网!"

day = new Date( )

hr = day.getHours( )

if (( hr >=0 ) && (hr <= 4 ))

mess1= "夜深了,逍湘提醒您要注意身体哦..."

if (( hr >= 4 ) && (hr < 7))

mess1=" 清晨好,您可真早呀!吃早餐了吗?"

if (( hr >= 7 ) && (hr < 12))

mess1=" 上午好,您开始工作了? "

if (( hr >= 12) && (hr <= 19))

mess1= "下午好,您工作辛苦了!"

if ((hr >= 19) && (hr <= 23))

mess1= "晚上好,您真是分秒必争呀! "

document.write("<blink>")

document.write(mess1)

document.write("</blink>")

document.write(mess2)

// -->

</SCRIPT>

</FONT>

<p><hr>

<!-- 第三种形式 -->

<div id="clock" ></div>

<SCRIPT language=Javascript1.2>

<!--

function show() {

 if(!document.layers && !document.all) return;

 var d = new Date();

 var iYear = d.getYear()

 var iMonth = d.getMonth()

 var iDay = d.getDate()

 var sWeek = d.getDay()

 var sHour = d.getHours()

 var sMinute = d.getMinutes()

 var sSecond = d.getSeconds()

 if(sWeek == 0) sWeek = "<font color=#ffffff>星期天</font>";

 if(sWeek == 1) sWeek = "星期一";

 if(sWeek == 2) sWeek = "星期二";

 if(sWeek == 3) sWeek = "星期三";

 if(sWeek == 4) sWeek = "星期四";

 if(sWeek == 5) sWeek = "星期五";

 if(sWeek == 6) sWeek = "<font color=#ffffff>星期六</font>";

 if(sHour <= 9) sHour = "0" + sHour;

 if(sMinute <= 9) sMinute = "0" + sMinute;

 if(sSecond <= 9) sSecond = "0" + sSecond;

 sClock = "&nbsp;&nbsp;" + iYear + "年" + (iMonth + 1) + "月" + iDay + "日 " + sWeek

    + " " + sHour + ":" + sMinute + ":" + sSecond;

 if(document.layers) {

    document.layers.clock.document.write(sClock);

    document.layers.clock.document.close();

 }

 else if(document.all)

    clock.innerHTML = sClock;

 setTimeout("show()", 1000);

}

show();

//-->

</SCRIPT>

<p><hr>

<!-- 第四种形式 -->

<FONT color=#ff0033>

      <DIV id=jnkc></DIV>

<SCRIPT>

setInterval("jnkc.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt (new Date().getDay());",1000);

</SCRIPT>

</FONT>

<p><hr>

</center>

</body>

</html>

--------------------------   InputDateTimeForm.java -------------------------------

/*

 * Generated by MyEclipse Struts

 * Template path: templates/java/JavaClass.vtl

 */

package com.qqtime.datetime;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

/**

 * MyEclipse Struts

 * Creation date: 08-07-2007

 *

 * XDoclet definition:

 * @struts.form name="inputDateTimeForm"

 */

public class InputDateTimeForm extends ActionForm {

       /*

        * Generated fields

        */

       /** month property */

       private String month;

       /** day property */

       private String day;

       /** year property */

       private String year;

       /** minute property */

       private String minute;

       /** second property */

       private String second;

       /** hours property */

       private String hours;

       /*

        * Generated Methods

        */

       /**

        * Method validate

        * @param mapping

        * @param request

        * @return ActionErrors

        */

       public ActionErrors validate(ActionMapping mapping,

                     HttpServletRequest request) {

              // TODO Auto-generated method stub

              return null;

       }

       /**

        * Method reset

        * @param mapping

        * @param request

        */

       public void reset(ActionMapping mapping, HttpServletRequest request) {

              // TODO Auto-generated method stub

              year="1984";

              month="06";

              day="26";

              hours="00";

              minute="00";

              second="00";

       }

       /**

        * Returns the month.

        * @return String

        */

       public String getMonth() {

              return month;

       }

       /**

        * Set the month.

        * @param month The month to set

        */

       public void setMonth(String month) {

              this.month = month;

       }

       /**

        * Returns the day.

        * @return String

        */

       public String getDay() {

              return day;

       }

       /**

        * Set the day.

        * @param day The day to set

        */

       public void setDay(String day) {

              this.day = day;

       }

       /**

        * Returns the year.

        * @return String

        */

       public String getYear() {

              return year;

       }

       /**

        * Set the year.

        * @param year The year to set

        */

       public void setYear(String year) {

              this.year = year;

       }

       /**

        * Returns the minute.

        * @return String

        */

       public String getMinute() {

              return minute;

       }

       /**

        * Set the minute.

        * @param minute The minute to set

        */

       public void setMinute(String minute) {

              this.minute = minute;

       }

       /**

        * Returns the second.

        * @return String

        */

       public String getSecond() {

              return second;

       }

       /**

        * Set the second.

        * @param second The second to set

        */

       public void setSecond(String second) {

              this.second = second;

       }

       /**

        * Returns the hours.

        * @return String

        */

       public String getHours() {

              return hours;

       }

       /**

        * Set the hours.

        * @param hours The hours to set

        */

       public void setHours(String hours) {

              this.hours = hours;

       }

}

----------------------- InputDateTimeAction.java ---------------------------------

/*

 * Generated by MyEclipse Struts

 * Template path: templates/java/JavaClass.vtl

 */

package com.qqtime.datetime;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

/**

 * MyEclipse Struts

 * Creation date: 08-07-2007

 *

 * XDoclet definition:

 * @struts.action path="/inputDateTime" name="inputDateTimeForm" input="datetime/inputDateTime.jsp" scope="request" validate="true"

 */

public class InputDateTimeAction extends Action {

       /*

        * Generated Methods

        */

       /**

        * Method execute

        * @param mapping

        * @param form

        * @param request

        * @param response

        * @return ActionForward

        */

       public ActionForward execute(ActionMapping mapping, ActionForm form,

                     HttpServletRequest request, HttpServletResponse response) {

              InputDateTimeForm inputDateTimeForm = (InputDateTimeForm) form;// TODO Auto-generated method stub

              int year=Integer.parseInt(inputDateTimeForm.getYear());

              int month=Integer.parseInt(inputDateTimeForm.getMonth());

              int day=Integer.parseInt(inputDateTimeForm.getDay());

              int hours=Integer.parseInt(inputDateTimeForm.getHours());

              int minute=Integer.parseInt(inputDateTimeForm.getMinute());

              int second=Integer.parseInt(inputDateTimeForm.getSecond());

              String errors="";

              if( 70>year || year>275760 || year%1!=0 ){

                     errors="对不起!您不可能在那个年代出生,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");

              }

              else if( 1>month || month>12 || month%1!=0){

                     errors="对不起!您输入的月份错误,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");      

              }

              else if( 1>day || day>31 || day%1!=0 ){

                     errors="对不起!您输入的日数错误,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");

              }

              else if( 0>hours || hours>23 || hours%1!=0 ){

                     errors="对不起!您输入的小时错误,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");

              }

              else if( 0>minute || minute>59 || minute%1!=0){

                     errors="对不起!您输入的分钟错误,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");

              }

              else if( 0>second || second>59 || second%1!=0){

                     errors="对不起!您输入的秒数错误,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");

              }

              else if( 0>second || second>59 || second%1!=0){

                     errors="对不起!您输入的秒数错误,请重新输入。";

                     request.setAttribute("error_inputDateTime", errors);

                     return new ActionForward("/datetime/inputDateTime.jsp");

              }           

              request.setAttribute("error_inputDateTime", errors);         

              return new ActionForward("/datetime/compute.jsp");        

       }

}

----------------------- 8、计算生日java类:Shengri.java ------------------------------

package bean;

import java.text.DateFormat;

import java.util.Date;

import javax.swing.JOptionPane;

public class Shengri {

       public String shengriDay(int byear,int bmonth,int bday,int hours,int minute,int second){

              Date nowdate=new Date();         //创建当前时期变量

              int nowyear=nowdate.getYear();   //

              int nowmonth=nowdate.getMonth(); //

              int nowday=nowdate.getDate();    //            

           //-----------计算出现在的岁数------------------------------------------------------------------

              if (nowyear < 100)

                     nowyear += 1900;

              int yourage = nowyear - byear;

              if (nowmonth < bmonth)

                     yourage--;

              if ((nowmonth == bmonth) && (nowday < bday))

                     yourage--;

              //--------------------------------------------------------------------------------------------

              try{

              Date enday =DateFormat.getDateInstance().parse(byear+"-"+bmonth+"-"+bday+" "+"00:00:00");//获取出生日期

              int secsPerDay = 1000 ; //毫秒

              int minPerDay = 60 * 1000 ;//一分钟有多少毫秒

              int hoursPerDay = 60 * 60 * 1000;//一小时有多少毫秒

              int PerDay = 24 * 60 * 60 * 1000;//一天有多少毫秒

              //-----------计算出离下一岁生日的 秒数------------------------------------------------------------------

              int secsRemain=nowdate.getSeconds();

              if(0<=second && second>=59){

                     if(second < nowdate.getSeconds()){

                            secsRemain=60-nowdate.getSeconds()+second;

                     }

                     else if(second > nowdate.getSeconds()){

                            secsRemain=second-nowdate.getSeconds();

                     }

              }

              else{

                     secsRemain=nowdate.getSeconds();

              }

              //------------------------------------------------------------------------------------------------------

           //-----------计算出离下一岁生日的 分钟数-----------------------------------------------------------------

              int minRemain=60-nowdate.getMinutes();

              if(0<=minute && minute<=59){

                     if(minute < nowdate.getMinutes()){

                            minRemain=60-nowdate.getMinutes()+minute;

                     }

                     else if(minute>=nowdate.getMinutes()){

                            minRemain=minute-nowdate.getMinutes();

                     }                  

              }

              else{

                     minRemain=60-nowdate.getMinutes();

              }

              //------------------------------------------------------------------------------------------------------

              //-----------计算出离下一岁生日的 小时数-----------------------------------------------------------------

              int hoursRemain=24-nowdate.getHours();

              if( 0<=hours && hours<=23){

                     if((hours < nowdate.getHours())){

                            hoursRemain=24-nowdate.getHours()+hours;

                     }

                     else if((hours >= nowdate.getHours())){

                            hoursRemain=hours-nowdate.getHours();

                     }                                       

              }

              else{

                     hoursRemain=24-nowdate.getHours();

              }

              //------------------------------------------------------------------------------------------------------

              //-----------计算出离下一岁生日的 天数-------------------------------------------------------------------

              long daysRemain=0;

              if(enday.getMonth() < nowdate.getMonth()){

                     enday.setYear(nowdate.getYear()+1);

                     double daysLeft = (( enday.getTime() - nowdate.getTime() ) / PerDay);

                     daysLeft =(daysLeft - 0.5);

                     long daysRound = Math.round(daysLeft);

                     daysRemain = daysRound;                  

              }

              else if(enday.getMonth() >= nowdate.getMonth()){

                     enday.setYear(nowdate.getYear());

                     double daysLeft = ((enday.getTime() - nowdate.getTime() ) / PerDay);

                     daysLeft =(daysLeft - 0.5);

                     long daysRound = Math.round(daysLeft);

                     daysRemain = daysRound;                  

              }

              //------------------------------------------------------------------------------------------------------

              //完整的显示语句

              String shengriDay = daysRemain + "" + hoursRemain + "小时" + minRemain + "分钟" + secsRemain + "";

              //System.out.println(daysLeft);

              return shengriDay;

              }catch(Exception e){

                     e.printStackTrace();

              }

              return null;

       }

       /**

        * @param args

        */

       public static void main(String[] args) {

              // TODO 自动生成方法存根

              int byear=Integer.parseInt(JOptionPane.showInputDialog("请输入你的出生年份", 1984));

              int bmonth=Integer.parseInt(JOptionPane.showInputDialog("请输入你的出生月份", 5));

              int bday=Integer.parseInt(JOptionPane.showInputDialog("请输入你的出生日", 25));

              int hours=Integer.parseInt(JOptionPane.showInputDialog("请输入你的出生小时", 00));

              int minute=Integer.parseInt(JOptionPane.showInputDialog("请输入你的出生分钟",00));

              int second=Integer.parseInt(JOptionPane.showInputDialog("请输入你的出生秒", 00));

              String bdate=new Shengri().shengriDay(byear, bmonth, bday,hours,minute,second);

              System.out.println(bdate);

       }

}

--------------------------- 9、计算属相java类:Shengxiao.java ----------------

package bean;

import java.util.Calendar;

import java.util.Date;

import javax.swing.JOptionPane;

public class Shengxiao {

       /**

        * 根据年份计算出您属什么

        * (鼠、牛、虎、免、龙、蛇、马、羊、猴、鸡、狗、猪)

        * @param birthyear(出生年份)

        * @return 属什么

        */

       public String shu(int birthyear){

              int toyear=1984;

              //String birthyear1=JOptionPane.showInputDialog("请输入你的出生年份", 1984);      

              //int birthyear=Integer.parseInt(birthyear1);

              String birthpet="";

              int x=(toyear-birthyear)%12;

              if(Integer.toString(birthyear)!=null){

        if((x == 0)){

            birthpet="您属鼠" ;    

        }

       else{

             if((x == 1)||(x == -11)){

                 birthpet="您属牛" ;        

             }

             else{

                  if((x == 2) || (x == -10)){

                      birthpet="您属虎" ;       

                  }

                  else{

                       if((x == 3)||(x == -9)){

                           birthpet="您属兔";        

                       }

                       else{

                            if((x == 4)||(x == -8)){

                                birthpet="您属龙";        

                            }

                            else{

                                    if((x == 5)||(x == -7)){

                                           birthpet="您属蛇";  

                                    }

                                    else{

                                           if((x == 6)||(x == -6)){

                                                  birthpet="您属马";     

                                           }

                                           else{

                                                  if((x == 7)||(x == -5)){

                                                         birthpet="您属羊";     

                                                  }

                                                  else{

                                                         if((x == 8)||(x == -4)){

                                                                birthpet="您属猴";    

                                                         }

                                                         else{

                                                                if((x == 9)||(x == -3)){

                                                                       birthpet="您属鸡";   

                                                                }

                                                                else{

                                                                       if((x == 10)||(x == -2)){

                                                                              birthpet="您属狗";       

                                                                       }

                                                                       else{

                                                                              if((x == 11)||(x == -1)){

                                                                                     birthpet="您属猪";        

                                                                              }

                                                                       }

                                                               }

                                                        }

                                                 }

                                          }

                                   }

                            }

                        }

                    }

                }

             }                

              return birthpet;

              }else{

                     return "请输入你的出生年份";

              }

       }

       /**

        * @param args

        */

       public static void main(String[] args) {

              // TODO 自动生成方法存根

              //String birthyear1=JOptionPane.showInputDialog("请输入你的出生年份", 1984);      

              //int birthyear=Integer.parseInt(birthyear1);

              System.out.print(new Shengxiao().shu(0));

       }

}

----------------------- 10、计算星座java类:Xingzuo.java ---------------------------

package bean;

publicclass Xingzuo {

   

   

   

    public String xingZuo(int xmonth,int xday){

        String xingzuo="";     

        if( (1==xmonth && xday>=22 && xday<=31) || (2==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="水瓶座";

        }

        elseif( (2==xmonth && xday>=22 && xday<=29) || (3==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="双鱼座";

        }

        elseif( (3==xmonth && xday>=22 && xday<=31) || (4==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="白羊座";

        }

        elseif( (4==xmonth && xday>=22 && xday<=30) || (5==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="金牛座";

        }

        elseif( (5==xmonth && xday>=22 && xday<=31) || (6==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="双子座";

        }

        elseif( (6==xmonth && xday>=22 && xday<=30) || (7==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="巨蟹座";

        }

        elseif( (7==xmonth && xday>=22 && xday<=31) || (8==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="狮子座";

        }

        elseif( (8==xmonth && xday>=22 && xday<=31) || (9==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="处女座";

        }

        elseif( (9==xmonth && xday>=22 && xday<=30) || (10==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="天秤座";

        }

        elseif( (10==xmonth && xday>=22 && xday<=31) || (11==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="天蝎座";

        }

        elseif( (11==xmonth && xday>=22 && xday<=30) || (12==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="射手座";

        }

        elseif( (12==xmonth && xday>=22 && xday<=31) || (1==xmonth && 1<=xday&&xday<=21) ){

            xingzuo="摩羯座";

        }

        else{

            xingzuo="对不起!您输入的日期不存在";

        }

        return xingzuo;

    }

    /**

     *@paramargs

     */

    publicstaticvoid main(String[] args) {

        // TODO自动生成方法存根

        System.out.print(new Xingzuo().xingZuo(6, 0));

    }

}

posted on 2010-08-09 00:10 逍湘 阅读(1100) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

留言簿(2)

随笔档案(49)

文章档案(17)

最新随笔

积分与排名

  • 积分 - 25770
  • 排名 - 1500

最新评论

阅读排行榜