Function changedate (VAL ){
VaR currdate = Document. getelementbyid ("txt_time ");
VaR date = new date ();
If (val = 0 ){
Currdate. value = date. getyear () + "-" + (date. getmonth () + 1) + "-" + date. getdate ();
}
Else {
If (chkdate (currdate. Value )){
VaR dates = currdate. value. Split ("-");
Dates [1] = dates [1]. Replace (/^ 0/G ,'');
Dates [2] = dates [2]. Replace (/^ 0/G ,'');
VaR da = dayadddiff (parseint (dates [0]), parseint (dates [1]), parseint (dates [2]), Val );
}
Else {
VaR da = dayadddiff (parseint (date. getyear (), parseint (date. getmonth () + 1), parseint (date. getdate (), Val );
}
Currdate. value = da;
}
Document. All. form1.ipsearch. onclick ();
}
Function dayadddiff (year, month, day, diff)
{
VaR numdays = new array (, 30, 31 );
VaR isleap = false;
VaR newyear = year;
VaR newmonth = month-1;
VaR n = numdays [newmonth];
VaR newday = Day;
VaR newdiff = diff;
VaR ln;
If (newmonth = 0)
Ln = 31;
Else if (newmonth = 11)
Ln = 31;
Else
Ln = numdays [newmonth + 1];
If (diff! = 0 ){
// Determine whether to renew the service
If (Year % 4 = 0 ){
If (Year % 100! = 0)
Isleap = true;
Else {
If (Year % 400 = 0)
Isleap = true;
}
}
If (newmonth = 1 & isleap)
++ N;
If (newmonth = 0 & isleap)
++ Ln;
// Value added
VaR newday = day + newdiff;
If (newday> 0 ){
If (newday> N ){
Newday = newday-N;
If (newmonth = 11)
{
Newmonth = 0;
Newyear + = 1;
Newdiff = newday-1;
Return dayadddiff (newyear, newmonth + 1, 1, newdiff );
}
Else {
Newmonth + = 1
Newdiff = newday-1;
Return dayadddiff (newyear, newmonth + 1, 1, newdiff );
}
}
}
Else if (newday = 0 ){
If (newmonth = 0)
{
Newmonth = 11
Newyear + =-1;
Newday = 31;
}
Else {
Newmonth + =-1
Newday = numdays [newmonth];
}
}
Else {
If (newmonth = 0)
{
Newmonth = 11
Newyear + =-1;
Newdiff = newday;
Newday = 31;
Return dayadddiff (newyear, newmonth + 1, newday, newdiff );
}
Else {
Newmonth + =-1;
Newdiff = newday;
Newday = ln;
Return dayadddiff (newyear, newmonth + 1, newday, newdiff );
}
}
}
// Output string
VaR daystring = "";
Daystring + = year;
Newmonth + = 1;
// If (newmonth <10)
// Daystring + = "-0" + newmonth;
// Else
Daystring + = "-" + newmonth;
// If (newday <10)
// Daystring + = "-0" + newday;
// Else
Daystring + = "-" + newday;
Return daystring;
}
Function chkdate (datestr ){
VaR lthdatestr
If (datestr! = "")
Lthdatestr = datestr. length;
Else
Lthdatestr = 0;
VaR tmpy = "";
VaR tmpm = "";
VaR tmpd = "";
VaR datestr;
VaR status;
Status = 0;
If (lthdatestr = 0)
// Alert ("the date cannot be blank! ")
Return false;
For (I = 0; I <lthdatestr; I ++ ){
If (datestr. charat (I) = '-'){
Status ++;
}
If (status> 2 ){
// Alert ("Date Format error! ");
Return false;
}
If (status = 0) & (datestr. charat (I )! = '-')){
Tmpy = tmpy + datestr. charat (I)
}
If (status = 1) & (datestr. charat (I )! = '-')){
Tmpm = tmpm + datestr. charat (I)
}
If (status = 2) & (datestr. charat (I )! = '-')){
Tmpd = tmpd + datestr. charat (I)
}
}
Year = new string (tmpy );
Month = new string (tmpm );
Day = new string (tmpd)
Tempdate = new string (Year + month + Day );
// Alert (tempdate );
If (tmpy. length! = 4) | (tmpm. length> 2) | (tmpd. length> 2 )){
// Alert ("Date Format error! ");
Return false;
}
If (! (1 <= month) & (12> = month) & (31> = day) & (1 <= day ))){
// Alert ("Date Format error! ");
Return false;
}
If (! (Year % 4) = 0) & (month = 2) & (Day = 29 )){
// Alert ("Date Format error! ");
Return false;
}
If (month <= 7) & (month % 2) = 0) & (day> = 31 )){
// Alert ("Date Format error! ");
Return false;
}
If (month> = 8) & (month % 2) = 1) & (day> = 31 )){
// Alert ("Date Format error! ");
Return false;
}
If (month = 2) & (Day = 30 )){
// Alert ("Date Format error! ");
Return false;
}
// Alert ("right ");
Return true;
}
</SCRIPT>
Select time: <asp: textbox id = "txt_time" runat = "server"> </ASP: textbox>
<Input id = "ipsearch" type = "button" value = "OK" class = "btn_57" onclick = "updatesrc ()"/>
& Nbsp;
<A href = "javascript:" onclick = "javascript: changedate (-1)"> previous day </a> & nbsp;
<A href = "javascript:" onclick = "javascript: changedate (0)"> today </a> & nbsp;
<A href = "javascript:" onclick = "javascript: changedate (1)"> the next day </a>