A calendar input space program, I changed, added the input of hours, minutes

Source: Internet
Author: User
Tags date1 idate

Calendar. js

Function getNowDate ()
{
Var nn = new Date ();
Year1 = nn. getYear ();
Mon1 = nn. getMonth () + 1;
Date1 = nn. getDate ();
Var monstr1;
Var datestr1
If (mon1 <10)
Monstr1 = "0" + mon1;
Else
Monstr1 = "" + mon1;

If (date1 <10)
Datestr1 = "0" + date1;
Else
Datestr1 = "" + date1;
Return year1 + "-" + monstr1 + "-" + datestr1;
}
Function getlastweekDate ()
{
Var nn = new Date ();
Year1 = nn. getYear ();
Mon1 = nn. getMonth () + 1;
Date1 = nn. getDate ();

Var mm = new Date (year1, mon1-1, date1 );
Var tmp1 = new Date (2000,1, 1 );
Var tmp2 = new Date (2000,1, 15 );
Var ne = tmp2-tmp1;
Var mm2 = new Date ();
Mm2.setTime (mm. getTime ()-ne );


Year2 = mm2.getYear ();
Mon2 = mm2.getMonth () + 1;
Date2 = mm2.getDate ();


If (mon2 <10)
Monstr2 = "0" + mon2;
Else
Monstr2 = "" + mon2;

If (date2 <10)
Datestr2 = "0" + date2;
Else
Datestr2 = "" + date2;
 

Return year2 + "-" + monstr2 + "-" + datestr2;
}

Var gdCtrl = new Object ();
Var goSelectTag = new Array ();
Var gcGray = "#808080 ";
// Var gcToggle = "# FB8664 ";
Var gcToggle = "# 7777ff ";
// Var gcBG = "# e5e6ec ";
Var gcBG = "# ffffff ";
Var previousObject = null;

Var gdCurDate = new Date ();
Var giYear = gdCurDate. getFullYear ();
Var giMonth = gdCurDate. getMonth () + 1;
Var giDay = gdCurDate. getDate ();
Var giHour = "00 ";
Var giMinute = "00 ";

Function fSetDate (iYear, iMonth, iDay, iHour, iMinute ){
VicPopCal. style. visibility = "hidden ";
If (iYear = 0) & (iMonth = 0) & (iDay = 0 )){
GdCtrl. value = "";
} Else {
IMonth = iMonth + 100 + "";
IMonth = iMonth. substring (1 );
IDay = iDay + 100 + "";
IDay = iDay. substring (1 );
IHour = iHour + 100 + "";
IHour = iHour. substring (1 );
IMinute = iMinute + 100 + "";
IMinute = iMinute. substring (1 );

If (gdCtrl. tagName = "INPUT "){
GdCtrl. value = iYear + "-" + iMonth + "-" + iDay + "" + iHour + ":" + iMinute;
} Else {
GdCtrl. innerText = iYear + "-" + iMonth + "-" + iDay + "" + iHour + ":" + iMinute;
}
}

For (I in goSelectTag)
GoSelectTag [I]. style. visibility = "visible ";
GoSelectTag. length = 0;

Window. returnValue = gdCtrl. value;
// Window. close ();
// Qhk add
If (yearNameObject! = Null & monthNameObject! = Null & dateNameObject! = Null)
{
If (gdCtrl. value = "")
{
YearNameObject. value = "";
MonthNameObject. value = "";
DateNameObject. value = "";
}
Else
{
YearNameObject. value = gdCtrl. value. substring (0, 4 );
MonthNameObject. value = gdCtrl. value. substring (5, 7 );
DateNameObject. value = gdCtrl. value. substring (8, 10 );
}
YearNameObject = null;
MonthNameObject = null;
DateNameObject = null;
}
}

Function HiddenDiv ()
{
Var I;
VicPopCal. style. visibility = "hidden ";
// Masked by Guozhong Zhang/Precom
For (I in goSelectTag)
GoSelectTag [I]. style. visibility = "visible ";
GoSelectTag. length = 0;

}
Function fSetSelected (aCell ){
Var iOffset = 0;
Var iYear = parseInt (tbSelYear. value );
Var iMonth = parseInt (tbSelMonth. value );
Var iHour = parseInt (tbSelHour. value );
Var iMinute = parseInt (tbSelMinute. value );

ACell. bgColor = gcBG;
With (aCell. children ["cellText"]) {
Var iDay = parseInt (innerText );
If (color = gcGray)
IOffset = (Victor <10 )? -1:1;
IMonth + = iOffset;
If (iMonth <1 ){
IYear --;
IMonth = 12;
} Else if (iMonth> 12 ){
IYear ++;
IMonth = 1;
}
}
FSetDate (iYear, iMonth, iDay, iHour, iMinute );
}

Function Point (iX, iY ){
This. x = iX;
This. y = iY;
}

Function fBuildCal (iYear, iMonth ){
Var aMonth = new Array ();
For (I = 1; I <7; I ++)
AMonth [I] = new Array (I );

Var dCalDate = new Date (iYear, iMonth-1, 1 );
Var iDayOfFirst = dCalDate. getDay ();
Var iDaysInMonth = new Date (iYear, iMonth, 0). getDate ();
Var iOffsetLast = new Date (iYear, iMonth-1, 0). getDate ()-iDayOfFirst + 1;
Var iDate = 1;
Var iNext = 1;

For (d = 0; d <7; d ++)
AMonth [1] [d] = (d <iDayOfFirst )? -(IOffsetLast + d): iDate ++;
For (w = 2; w <7; w ++)
For (d = 0; d <7; d ++)
AMonth [w] [d] = (iDate <= iDaysInMonth )? IDate ++:-(iNext ++ );
Return aMonth;
}

Function fDrawCal (iYear, iMonth, iCellHeight, sDateTextSize ){
Var WeekDay = new Array ("day", "one", "two", "three", "four", "five", "Six ");
Var styleTD = "bgcolor = '" + gcBG + "'bordercolor ='" + gcBG + "'valign = 'middle' align = 'center' height = '" + iCellHeight +" 'style = 'font: arial "+ sDateTextSize +"; "; // Coded by Liming Weng (Victor Won) email: victorwon@sina.com

With (document ){
For (w = 1; w <7; w ++ ){
Write ("<tr> ");
For (d = 0; d <7; d ++ ){
Write ("<td id = calCell" + styleTD + "cursor: hand; 'onmouseover = 'this. bgColor = gcToggle 'onmouseout = 'this. bgColor = gcBG 'onclick = 'fsetselected (this) '> ");
Write ("<font id = cellText Victor = 'liming weng' size = 2> </font> ");
Write ("</td> ");
Write ("<TD> ");

}
Write ("</tr> ");
}
}
}

Function fUpdateCal (iYear, iMonth ){
MyMonth = fBuildCal (iYear, iMonth );
Var I = 0;
For (w = 0; w <6; w ++)
For (d = 0; d <7; d ++)
With (cellText [(7 * w) + d]) {
Victor = I ++;
If (myMonth [w + 1] [d] <0 ){
Color = gcGray;
InnerText =-myMonth [w + 1] [d];
} Else {
Color = (d = 0) | (d = 6 ))? "Red": "black ";
InnerText = myMonth [w + 1] [d];
}
}
}

Function fSetYearMon (iYear, iMon ){
TbSelMonth. options [iMon-1]. selected = true;
For (I = 0; I <tbSelYear. length; I ++)
If (tbSelYear. options [I]. value = iYear)
TbSelYear. options [I]. selected = true;
FUpdateCal (iYear, iMon );
}

Function fPrevMonth (){
Var iMon = tbSelMonth. value;
Var iYear = tbSelYear. value;

If (-- iMon <1 ){
IMon = 12;
IYear --;
}

FSetYearMon (iYear, iMon );
}

Function fNextMonth (){
Var iMon = tbSelMonth. value;
Var iYear = tbSelYear. value;

If (++ iMon> 12 ){
IMon = 1;
IYear ++;
}

FSetYearMon (iYear, iMon );
}

Function fToggleTags (){
With (document. all. tags ("SELECT ")){
For (I = 0; I <length; I ++)
If (item (I). Victor! = "Won") & fTagInBound (item (I ))){
Item (I). style. visibility = "hidden ";
GoSelectTag [goSelectTag. length] = item (I );
}
}
}

Function fTagInBound (aTag ){
With (VicPopCal. style ){
Var l = parseInt (left );
Var t = parseInt (top );
Var r = l + parseInt (width );
Var B = t + parseInt (height );
Var ptLT = fGetXY (aTag );
Return! (PtLT. x> r) | (ptLT. x + aTag. offsetWidth <l) | (ptLT. y> B) | (ptLT. y + aTag. offsetHeight <t ));
}
}

Function fGetXY (aTag ){
Var oTmp = aTag;
Var pt = new Point (0, 0 );
Do {
Pt. x + = oTmp. offsetLeft;
Pt. y + = oTmp. offsetTop;
OTmp = oTmp. offsetParent;
} While (oTmp. tagName! = "BODY ");
Return pt;
}

// Main: popCtrl is the widget beyond which you want this calendar to appear;
// DateCtrl is the widget into which you want to put the selected date.
// I. e.: <input type = "text" name = "dc" style = "text-align: center "readonly> <INPUT type =" button "value =" V "onclick =" fPopCalendar (dc, dc); return false ">
Function fPopCalendar (popCtrl, dateCtrl, strDate ){
If (popCtrl = previousObject ){
If (VicPopCal. style. visibility = "visible "){
HiddenDiv ();
Return true;
}

}
PreviousObject = popCtrl;
GdCtrl = dateCtrl;
FInitialDate (strDate );
FSetYearMon (giYear, giMonth );
Var point = fGetXY (popCtrl );
With (VicPopCal. style ){
Left = point. x;
Top = point. y + popCtrl. offsetHeight;
Width = VicPopCal. offsetWidth;
// Added by Danian Zhang/SUI
// Width = 210;
// Modified by Guozhong Zhang/Precom
Length = 295;
Height = VicPopCal. offsetHeight;
// Cover the Object under it
FToggleTags (point );
Visibility = 'visible ';
}
}
// The program that uses three input (or select) items as the date input does not want to modify the action. You can call the following function to use the date as the hidden field.
Var yearNameObject;
Var monthNameObject;
Var dateNameObject;
Function newfPopCalendar (popCtrl, dateCtrl, yearName, monthName, dateName, strDate)
{
FPopCalendar (popCtrl, dateCtrl, strDate );
If (document. all. item (yearName). length = null)
{
YearNameObject = document. all. item (yearName );
MonthNameObject = document. all. item (monthName );
DateNameObject = document. all. item (dateName );
}
Else
{
YearNameObject = document. all. item (yearName) [document. all. item (yearName). length-1];
MonthNameObject = document. all. item (monthName) [document. all. item (monthName). length-1];
DateNameObject = document. all. item (dateName) [document. all. item (dateName). length-1];
}
}
// Qhk -- end
// Added by Danian Zhang/SUI
Function fInitialDate (strDate ){
If (strDate = null | strDate. length! = 10)
Return false;

Var sYear = strDate. substring (0, 4 );
Var sMonth = strDate. substring (5, 7 );
Var sDay = strDate. substring (8, 10 );

If (sMonth. charAt (0) = '0') {sMonth = sMonth. substring (1, 2 );}
If (sDay. charAt (0) = '0') {sDay = sDay. substring (1, 2 );}

Var nYear = parseInt (sYear );
Var nMonth = parseInt (sMonth );
Var nDay = parseInt (sDay );
 
If (isNaN (nYear) return false;
If (isNaN (nMonth) return false;
If (isNaN (nDay) return false;

Var arrMon = new Array (12 );
ArrMon [0] = 31; arrMon [1] = nYear % 4 = 0? 29:28;
ArrMon [2] = 31; arrMon [3] = 30;
ArrMon [4] = 31; arrMon [5] = 30;
ArrMon [6] = 31; arrMon [7] = 31;
ArrMon [8] = 30; arrMon [9] = 31;
ArrMon [10] = 30; arrMon [11] = 31;

If (nYear <1900 | nYear> 2100) return false;
If (nMonth <1 | nMonth> 12) return false;
If (nDay <1 | nDay> arrMon [nMonth-1]) return false;

GiYear = nYear;
GiMonth = nMonth;
GiDay = nDay;
Return true;
}

Var gMonths = new Array ", "August September", "August October", "August November", "August December ");

With (document ){
// Modified by Guozhong Zhang/Precom
// Write ("<Div id = 'vicpopcal' style = 'overflow: hidden; POSITION: absolute; VISIBILITY: hidden; border: 2px ridge; z-index: 100; '> ");
Write ("<Div id = 'vicpopcal' style = 'overflow: hidden; POSITION: absolute; VISIBILITY: hidden; border: 2px ridge; z-index: 100; '> ");
Write ("<table border = '0' bgcolor = '# cccccccc'> ");
Write ("<TR> ");
Write ("<td valign = 'middle' align = 'center'> <input type = 'button 'name = 'prevmonth' value = '<'style = 'height: 20; width: 20; FONT: bold 'onclick = 'fprevmonth () '> ");
Write ("<SELECT name = 'tbselyear' onChange = 'fupdatecal (tbSelYear. value, tbSelMonth. value) 'Victor = 'won'> ");
// Modified by Guozhong Zhang/Precom
// For (I = 1900; I <2015; I ++)
For (I = 2000; I <2015; I ++)
Write ("<OPTION value = '" + I + "'>" + I + "</OPTION> ");
Write ("</SELECT> ");
Write ("<select name = 'tbselmonth' onChange = 'fupdatecal (tbSelYear. value, tbSelMonth. value) 'Victor = 'won'> ");
For (I = 0; I <12; I ++)
Write ("<option value = '" + (I + 1) + "'>" + gMonths [I] + "</option> ");
Write ("</SELECT> ");
Write ("<input type = 'button 'name = 'prevmonth' value = '> 'style = 'height: 20; width: 20; FONT: bold 'onclick = 'fnextmonth () '> ");
Write ("</td> ");
Write ("</TR> <TR> ");

Write ("<TD align = 'center'> ");
Write ("<TABLE width = '000000'> <TR> ");
Var WeekDay2 = new Array ("day", "one", "two", "three", "four", "five", "Six ");
For (I = 0; I <7; I ++ ){
Write ("<td color: #000000 'style = 'font: bold arial'> ");
// Added by Guozhong Zhang/Precom
Write ("<font size = 2> ");
Write (WeekDay2 [I]);
// Added by Guozhong Zhang/Precom
Write ("</font> ");
Write ("</td> ");
}
Write ("</tr> </table> ");
Write ("</TD> </TR> ");

Write ("<td align = 'center'> ");
// Modified by Guozhong Zhang/Precom
// Write ("<DIV style = 'background-color: Teal'> <table width = '000000' border = '0'> ");
Write ("<DIV style = 'background-color: white'> <table width = '000000' border = '0'> ");
FDrawCal (giYear, giMonth, 18, '12 ');
Write ("</table> </DIV> ");
Write ("</td> ");
Write ("</TR> <TD align = 'center'> ");
Write ("<TABLE width = '000000'> <TR> <TD align = 'center'> ");
Write ("<B style = 'cursor: hand 'onclick = 'fsetdate (0, 0, 0, 0) 'onMouseOver = 'this. style. color = gcToggle 'onmouseout = 'this. style. color = 0'> <font size = 2> clear </font> </B> ");
Write ("</td> <td align = 'center'> ");
Write ("<B style = 'cursor: hand 'onclick = 'fsetdate (giYear, giMonth, giDay,) 'onMouseOver = 'this. style. color = gcToggle 'onmouseout = 'this. style. color = 0'> <font size = 2> today: "+ giYear +"-"+ giMonth +"-"+ giDay +" </font> </B> ");
Write ("</td> </tr> </table> ");
Write ("</TD> ");

Write ("<TD style = 'color: gcToggle 'width = '80px '> <span style = 'top: 50; position: absolute; font-size: 12px 'width = '80px '> ");
Var gHour = new Array ("00", "01", "02", "03", "04", "05", "06", "07 ", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17 ", "18", "19", "20", "21", "22", "23 ");
Write ("& nbsp; <select name = 'tbselhour 'onChange = 'fupdatecal (tbSelYear. value, tbSelMonth. value) 'Victor = 'won'> ");
For (I = 0; I <24; I ++)
Write ("<option value = '" + gHour [I] + "'>" + gHour [I] + "</option> ");
Write ("</select> hour <br> ");

Var gMinute = new Array ("00", "01", "02", "03", "04", "05", "06", "07 ", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17 ", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27 ", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37 ", "38", "39", "40", "41", "42", "44", "45", "46", "47", "48 ", "49", "50", "51", "52", "54", "55", "56", "57", "58 ", "59 ");
Write ("& nbsp; <select name = 'tbselminute 'onChange = 'fupdatecal (tbSelYear. value, tbSelMonth. value) 'Victor = 'won' style = 'width: 40px '> ");
For (I = 0; I <59; I ++)
Write ("<option value = '" + gMinute [I] + "'>" + gMinute [I] + "</option> ");
Write ("</select> minute ");

Write ("</span> </TD> ");
Write ("</TR> ");

Write ("</TABLE> </Div> ");
}

Test.htm

<Html>
<Head>
<Title> test </title>
<Script language = "javascript" src = "calendar. js"> </script>
</Head>
<Body>
<Form action = "testc. jsp" name = "form1">
<P> News Date:
<Input type = "text" name = "news_date" readonly size = "20" onClick = "fPopCalendar (news_date, news_date); return false">
<Input type = "submit" value = "tijiao">
</Form>
</Body>


</Html>

Testc. jsp

<% @ Page language = "java" %>
<% @ Page import = "java. util. *" %>
<%
String datetime = request. getParameter ("news_date ");
Out. println (datetime );
%>

Function getNowDate ()
{
Var nn = new Date ();
Year1 = nn. getYear ();
Mon1 = nn. getMonth () + 1;
Date1 = nn. getDate ();
Var monstr1;
Var datestr1
If (mon1 <10)
Monstr1 = "0" + mon1;
Else
Monstr1 = "" + mon1;

If (date1 <10)
Datestr1 = "0" + date1;
Else
Datestr1 = "" + date1;
Return year1 + "-" + monstr1 + "-" + datestr1;
}
Function getlastweekDate ()
{
Var nn = new Date ();
Year1 = nn. getYear ();
Mon1 = nn. getMonth () + 1;
Date1 = nn. getDate ();

Var mm = new Date (year1, mon1-1, date1 );
Var tmp1 = new Date (2000,1, 1 );
Var tmp2 = new Date (2000,1, 15 );
Var ne = tmp2-tmp1;
Var mm2 = new Date ();
Mm2.setTime (mm. getTime ()-ne );

Year2 = mm2.getYear ();
Mon2 = mm2.getMonth () + 1;
Date2 = mm2.getDate ();

If (mon2 <10)
Monstr2 = "0" + mon2;
Else
Monstr2 = "" + mon2;

If (date2 <10)
Datestr2 = "0" + date2;
Else
Datestr2 = "" + date2;

Return year2 + "-" + monstr2 + "-" + datestr2;
}

Var gdCtrl = new Object ();
Var goSelectTag = new Array ();
Var gcGray = "#808080 ";
// Var gcToggle = "# FB8664 ";
Var gcToggle = "# 7777ff ";
// Var gcBG = "# e5e6ec &

 

# Display the IP address 210.77.176. * at 09:58:00, 2004-12-17 .*
Function getNowDate ()
{
Var nn = new Date ();
Year1 = nn. getYear ();
Mon1 = nn. getMonth () + 1;
Date1 = nn. getDate ();
Var monstr1;
Var datestr1
If (mon1 <10)
Monstr1 = "0" + mon1;
Else
Monstr1 = "" + mon1;

If (date1 <10)
Datestr1 = "0" + date1;
Else
Datestr1 = "" + date1;
Return year1 + "-" + monstr1 + "-" + datestr1;
}
Function getlastweekDate ()
{
Var nn = new Date ();
Year1 = nn. getYear ();
Mon1 = nn. getMonth () + 1;
Date1 = nn. getDate ();

Var mm = new Date (year1, mon1-1, date1 );
Var tmp1 = new Date (2000,1, 1 );
Var tmp2 = new Date (2000,1, 15 );
Var ne = tmp2-tmp1;
Var mm2 = new Date ();
Mm2.setTime (mm. getTime ()-ne );

Year2 = mm2.getYear ();
Mon2 = mm2.getMonth () + 1;
Date2 = mm2.getDate ();

If (mon2 <10)
Monstr2 = "0" + mon2;
Else
Monstr2 = "" + mon2;

If (date2 <10)
Datestr2 = "0" + date2;
Else
Datestr2 = "" + date2;

Return year2 + "-" + monstr2 + "-" + datestr2;
}

Var gdCtrl = new Object ();
Var goSelectTag = new Array ();
Var gcGray = "#808080 ";
// Var gcToggle = "# FB8664 ";
Var gcToggle = "# 7777ff ";
// Var gcBG = "# e5e6ec &
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.