|
Blue Forest http://www.lslnet.com at 6:28 p.m. on August 22, 2006
Javascript how come the day before and one day after day?
Using Javascript how come the day before and one day after day? |
Some Subtraction
[html]
"Script>
Document.write (new Date (1998,4))
"/script>
[/html] |
Js itself will help you automatically calculate the date
[html]
"Script>
Alert ( "a day :" + new Date ( "2003/1/1"))
Alert ( "the day before :" + new Date ( "2003/1/0"))
Alert ( "a day :" + new Date ( "2003/1/31"))
Alert ( "day :" + new Date ( "2003/1/32"))
"/script>
[/html] |
You are wrong, so I have not made myself clear :
How do you show the same day the day before and one day after the date date
For example : Today is 2003-7-15, then today is the day before : 2003-7-14, the day after is : 2003-7-16
(Because of the different number of days per month, so special attention should be paid to the first day and the last day of each month)
Will experts advise! |
Simple realization :
[html]
"Script>
With (new Date ()) (
Y=getYear ()
M=getMonth ()
D=getDate ()
}
Document.write ( "yesterday :" +new Date (Y, M, D-1) + "" School Official Cites Use ")
Document.write ( "Today :" +new Date () + "" School Official Cites Use ")
Document.write ( "Tomorrow :" +new Date (Y, M, D + 1) + "" School Official Cites Use ")
"/script>
[/html]
The number of days per month to consider :
[html]
"HTML>
"HEAD>
"Meta NAME=" generator "Content=" Microsoft Visual Studio 6.0, ""
"TITLE></TITLE>
"Style type=" text/css ""
<!--
. Mytd{
Border-top-width : 1px;
Border-right-width : 1px;
Border-bottom-width : 1px;
Border-left-width : 1px;
Border-top-style : solid;
Border-right-style : solid;
Border-bottom-style : solid;
Border-left-style : solid;
Border-top-color : #FDFEFD;
Border-right-color : #E5F3DF;
Border-bottom-color : #E5F3DF;
Border-left-color : #FDFEFD;
Color:#9FD389;
Font-family : "Arial Black";
Font-size : 12px;
Text-decoration : none;
}
. Mytab --
Border-top : 1px solid E5F3DF;
Border-right : 1px solid FDFEFD;
Border-bottom : 1px solid FDFEFD;
Border-left : 1px solid E5F3DF;a:link --
Color : FD5C98;
Text-decoration : none;
}
-->
"/style>
"Script language=" Javascript ""
Function showdate (sYear, sMonth)
{
Var week=new Array ( "Sun", "Mon", "Tue", "Wen", "The", "Fri" and "Sad");
Var Yday=new Array (2);
Yday[0]=new Array (0,31,28,31,30,31,30,31,31,30,31,30,30);
Yday[1]=new Array (0,31,29,31,30,31,30,31,31,30,31,30,30);
Var s=new Date (sYear, sMonth-1,1);
Var ≥, j, yn=0;
Var w=40, h=40; /// high and wide form
//// Testing is a leap year
If (sYear%400==0 | | sYear%100!=0, named sYear%4==0)
Yn=1;
The following code shows ////
Var oStr= ""
OStr+= "" table buying '0' cellpadding= '3' cellspacing '0' bgcolor= '#F4FAF1' formal 'mytab' ""
OStr+= "" tr> ";
OStr+= "" td formal 'mytd' save 'center', "defended the various factions' D:/sun/images/row.gif 'onclick=' showdate (" + (sMonth==1?sYear-1 : sYear) + "" + (sMonth==1?12:sMonth-1) + ") '" </img></td> ";
OStr+= "" td formal 'mytd' colspan= '5' save 'center' "" +s.getFullYear () + "-" + (s.getMonth () + 1) + "on the" = ";
OStr+= "" td formal 'mytd' save 'center', "defended the various factions' D:/sun/images/row.gif 'onclick=' showdate (" + (sMonth==12?sYear+1 : sYear) + "" + (sMonth==12?1:sMonth+1) + ") '" </img></td> ";
OStr+= "" Per ";
OStr+= "" tr> ";
For (j=0;j<7;j++)
{
OStr+= "" td formal 'mytd' width= "+w+" height "+h+" to save the 'center' "" +week[j]+ "" = ";
}
While (i<=Yday[yn][sMonth])
{
OStr+= "" tr> ";
For (j=0;j<7;j++)
{
I++;
If (i==1, named j!=s.getDay ())
{
OStr+= "" td formal 'mytd' width= "+w+" height "+h+" to save the 'center' "" = ";
I--;
}
Else if (i<=Yday[yn][sMonth])
OStr+= "" td class=\ "mytd\" width= "+w+" height "+h+" onMouseOver=\ "this.bgColor= '#EAF9E3' \" onMouseOut=\ "this.bgColor= '' \" save the 'center' "" +i+ "" patient " ;
Else
OStr+= "" td formal 'mytd' width= "+w+" height "+h+" to save the 'center' "" = ";
}
OStr+= "" Per ";
}
OStr+= "" ShapeID="_x0000_i1025" DrawAspect="Content" ObjectID="_1127825915"> </o:OLEObject> ";
Date.innerHTML=oStr;
//window.alert (Yday[yn][sMonth]);
}
Window.onload=function () {with (new Date ()) showdate (getYear (), getMonth () +1) ;}
"/script>
"/HEAD>
"BODY>
"Span id=date></span>
"/BODY>
"/HTML>
[/html] |
|