| « | November 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | | | |
| 公告 |
|
| Blog信息 |
|
blog名称: 日志总数:22 评论数量:55 留言数量:0 访问次数:130305 建立时间:2006年3月13日 |

| |
|
[java程序设计]日期js 软件技术
jjs_love 发表于 2006/4/18 13:10:08 |
|
Calendar.js
function Calendar(formatString) { var today = new Date(); this.currYear = today.getYear(); this.currMonth = today.getMonth(); this.currDate = today.getDate(); this.currHour = today.getHours(); this.currMinute = today.getMinutes(); this.currSecond = today.getSeconds(); this.currMeridiem = (this.currHour >= 12 ? 'PM' : 'AM'); var property = null;
var self = document.createElement('div'); self.className = "calendarBox"; self.eventHandler = this; self.onmouseover = function() { this.eventHandler.calendar_MouseEnter(this, event); }; self.onmouseout = function() { this.eventHandler.calendar_MouseOut(this, event); }; document.body.appendChild(self); this.width = 0; this.height = 0; this.top = 0; this.left = 0; this.offsetWidth = self.offsetWidth; this.offsetHeight = self.offsetHeight; Calendar.prototype.getHead = function(year, month) { var calendarHead = document.createElement('table'); calendarHead.width = "100%"; calendarHead.className = "head"; var tbody = document.createElement('tbody'); var ctrlBar = document.createElement('tr'); var btnPrevYear = document.createElement('td'); btnPrevYear.innerHTML = "7"; btnPrevYear.className = "ctrlButton"; btnPrevYear.align = "center"; btnPrevYear.valign = "middle"; btnPrevYear.eventHandler = this; btnPrevYear.onclick = function() { this.eventHandler.btnPrevYear_Click(this, event); }; btnPrevYear.onmouseover = function() { this.eventHandler.ctrlButton_RollOver(this, event); }; btnPrevYear.onmouseout = function() { this.eventHandler.ctrlButton_RollOut(this, event); }; var btnPrevMonth = document.createElement('td'); btnPrevMonth.className = "ctrlButton"; btnPrevMonth.innerHTML = "3"; btnPrevMonth.align = "center"; btnPrevMonth.valign = "middle"; btnPrevMonth.eventHandler = this; btnPrevMonth.onclick = function() { this.eventHandler.btnPrevYear_Click(this, event); }; btnPrevMonth.onmouseover = function() { this.eventHandler.ctrlButton_RollOver(this, event); }; btnPrevMonth.onmouseout = function() { this.eventHandler.ctrlButton_RollOut(this, event); }; var btnPrevMonth = document.createElement('td'); btnPrevMonth.className = "ctrlButton"; btnPrevMonth.innerHTML = "3"; btnPrevMonth.align = "center"; btnPrevMonth.valign = "middle"; btnPrevMonth.eventHandler = this; btnPrevMonth.onclick = function() { this.eventHandler.btnPrevMonth_Click(this, event); }; btnPrevMonth.onmouseover = function() { this.eventHandler.ctrlButton_RollOver(this, event); }; btnPrevMonth.onmouseout = function() { this.eventHandler.ctrlButton_RollOut(this, event); }; var btnNextMonth = document.createElement('td'); btnNextMonth.className = "ctrlButton"; btnNextMonth.innerHTML = "4"; btnNextMonth.align = "center"; btnNextMonth.valign = "middle"; btnNextMonth.eventHandler = this; btnNextMonth.onclick = function() { this.eventHandler.btnNextMonth_Click(this, event); }; btnNextMonth.onmouseover = function() { this.eventHandler.ctrlButton_RollOver(this, event); }; btnNextMonth.onmouseout = function() { this.eventHandler.ctrlButton_RollOut(this, event); }; var btnNextYear = document.createElement('td'); btnNextYear.className = "ctrlButton"; btnNextYear.innerHTML = "8"; btnNextYear.align = "center"; btnNextYear.valign = "middle"; btnNextYear.eventHandler = this; btnNextYear.onclick = function() { this.eventHandler.btnNextYear_Click(this, event); }; btnNextYear.onmouseover = function() { this.eventHandler.ctrlButton_RollOver(this, event); }; btnNextYear.onmouseout = function() { this.eventHandler.ctrlButton_RollOut(this, event); }; var title = document.createElement('td'); title.className = "title"; title.align = "center"; var sltYear = document.createElement('span'); sltYear.className = 'select'; sltYear.innerHTML = year; sltYear.eventHandler = this; sltYear.onclick = function() { this.eventHandler.sltMoreYear_Click(this, event); }; sltYear.onmouseover = function() { this.eventHandler.select_RollOver(this, event); }; sltYear.onmouseout = function() { this.eventHandler.select_RollOut(this, event); }; var sltMonth = document.createElement('span'); sltMonth.className = 'select'; sltMonth.innerHTML = subZero((month + 1), 2); sltMonth.eventHandler = this; sltMonth.onclick = function() { this.eventHandler.sltMoreMonth_Click(this, event); }; sltMonth.onmouseover = function() { this.eventHandler.select_RollOver(this, event); }; sltMonth.onmouseout = function() { this.eventHandler.select_RollOut(this, event); }; var spnBlank = document.createElement('span'); spnBlank.innerHTML = ' '; var spnYear = document.createElement('span'); spnYear.innerHTML = ' Äê '; var spnMonth = document.createElement('span'); spnMonth.innerHTML = ' ÔÂ '; title.appendChild(spnBlank); title.appendChild(sltYear); title.appendChild(spnYear); title.appendChild(sltMonth); title.appendChild(spnMonth); ctrlBar.appendChild(btnPrevYear); ctrlBar.appendChild(btnPrevMonth); ctrlBar.appendChild(title); ctrlBar.appendChild(btnNextMonth); ctrlBar.appendChild(btnNextYear); tbody.appendChild(ctrlBar); calendarHead.appendChild(tbody); return calendarHead; };
Calendar.prototype.getBody = function(year, month) { var calendarBody = document.createElement('table'); calendarBody.width = "100%"; calendarBody.className = "body"; var tbody = document.createElement('tbody'); tbody.appendChild(getWeekNames()); if (property == null) { property = new Array(monthDays(year, month)); } var day = 1; for (var rowLoop=0; rowLoop<6; rowLoop++) { var row = document.createElement('tr'); for (var colLoop=0; colLoop<7; colLoop++) { var col = document.createElement('td'); col.align = "center"; col.valign = "meddle"; if (rowLoop == 0 && colLoop < firstDayOfWeek(year, month)) { col.innerHTML = ' '; col.className = "none"; } else if (day <= monthDays(year, month)) { if (property[(day - 1)] != undefined && property[(day - 1)] != "") { var properties = property[(day - 1)].split("-"); if (properties[1] == properties[2] || properties[1] >= 3) { if (properties[1] == 4) { col.className = "examined"; } else if (properties[1] == 1) { col.className = "planed"; } else if (properties[1] == 2) { col.className = "summarized"; } } col.property = property[(day - 1)]; } else if (year == today.getYear() && month == today.getMonth() && day == today.getDate()) { col.className = "today"; } else if (year == this.currYear && month == this.currMonth && day == this.currDate) { col.className = "select"; } col.innerHTML = day++; if (colLoop == 0 || colLoop == 6) { col.id = "feast"; } col.eventHandler = this; col.ondblclick = function() { this.eventHandler.tdDay_DblClick(this, event); }; col.onclick = function() { this.eventHandler.tdDay_Click(this, event); }; } else { col.innerHTML = ' '; col.className = "none"; } row.appendChild(col); } tbody.appendChild(row); } function getWeekNames() { var row = document.createElement('tr'); row.className = "weekName"; var colSunday = document.createElement('td'); colSunday.innerHTML = 'Sun';//'ÐÇÆÚÈÕ'; colSunday.id = "feast"; colSunday.align = "center"; var colNonday = document.createElement('td'); colNonday.innerHTML = 'Non';//'ÐÇÆÚÒ»'; colNonday.align = "center"; var colTuesday = document.createElement('td'); colTuesday.innerHTML = 'Tue';//'ÐÇÆÚ¶þ'; colTuesday.align = "center"; var colWendnesday = document.createElement('td'); colWendnesday.innerHTML = 'Wen';//'ÐÇÆÚÈý'; colWendnesday.align = "center"; var colThursday = document.createElement('td'); colThursday.innerHTML = 'Thu';//'ÐÇÆÚËÄ'; colThursday.align = "center"; var colFriday = document.createElement('td'); colFriday.innerHTML = 'Fri';//'ÐÇÆÚÎå'; colFriday.align = "center"; var colSaturday = document.createElement('td'); colSaturday.innerHTML = 'Sat';//'ÐÇÆÚÁù'; colSaturday.id = "feast"; colSaturday.align = "center"; row.appendChild(colSunday); row.appendChild(colNonday); row.appendChild(colTuesday); row.appendChild(colWendnesday); row.appendChild(colThursday); row.appendChild(colFriday); row.appendChild(colSaturday); return row; } calendarBody.appendChild(tbody); return calendarBody; }; Calendar.prototype.getFoot = function(hour, minute, second) { var tabFoot = document.createElement('table'); tabFoot.width = "100%"; var tbody = document.createElement('tbody'); var tr = document.createElement('tr'); var td = document.createElement('td'); td.align = "right";
var sltMeridiem = document.createElement('span'); sltMeridiem.className = 'select'; sltMeridiem.innerHTML = this.currMeridiem; sltMeridiem.eventHandler = this; sltMeridiem.onclick = function() { this.eventHandler.btnMeridiem_Click(this, event); }; sltMeridiem.onmouseover = function() { this.eventHandler.select_RollOver(this, event); }; sltMeridiem.onmouseout = function() { this.eventHandler.select_RollOut(this, event); }; var sltHour = document.createElement('span'); sltHour.className = 'select'; if (formatString.indexOf("HH") > 0) { sltHour.innerHTML = subZero(hour, 2); } else if (formatString.indexOf("hh") > 0) { sltHour.innerHTML = subZero((hour == 0 || hour == 12 ? 12 : hour % 12), 2); } sltHour.eventHandler = this; sltHour.onclick = function() { this.eventHandler.btnHour_Click(this, event); }; sltHour.onmouseover = function() { this.eventHandler.select_RollOver(this, event); }; sltHour.onmouseout = function() { this.eventHandler.select_RollOut(this, event); }; var sltMinute = document.createElement('span'); sltMinute.className = 'select'; sltMinute.innerHTML = subZero(minute, 2); sltMinute.eventHandler = this; sltMinute.onclick = function() { this.eventHandler.btnMinute_Click(this, event); }; sltMinute.onmouseover = function() { this.eventHandler.select_RollOver(this, event); }; sltMinute.onmouseout = function() { this.eventHandler.select_RollOut(this, event); }; var sltSecond = document.createElement('span'); sltSecond.className = 'select'; sltSecond.innerHTML = subZero(second, 2); sltSecond.eventHandler = this; sltSecond.onclick = function() { this.eventHandler.btnSecond_Click(this, event); }; sltSecond.onmouseover = function() { this.eventHandler.select_RollOver(this, event); }; sltSecond.onmouseout = function() { this.eventHandler.select_RollOut(this, event); }; var spnBlank = document.createElement('span'); spnBlank.innerHTML = ' '; var spnColon = document.createElement('span'); spnColon.innerHTML = '<b> : </b>'; if (formatString.indexOf("am") > 0) { td.appendChild(sltMeridiem); } if (formatString.indexOf("am") > 0 && ((formatString.indexOf("mi") > 0) || (((formatString.indexOf("hh")) > 0 || (formatString.indexOf("HH") > 0)) || (formatString.indexOf("ss") > 0)))) { td.appendChild(spnBlank); } if ((formatString.indexOf("hh")) > 0 || (formatString.indexOf("HH") > 0)) { td.appendChild(sltHour); } if ((formatString.indexOf("mi") > 0) && (((formatString.indexOf("hh")) > 0 || (formatString.indexOf("HH"))))) { td.appendChild(spnColon); } if (formatString.indexOf("mi") > 0) { td.appendChild(sltMinute); } if ((formatString.indexOf("ss") > 0) && (((formatString.indexOf("hh")) > 0 || (formatString.indexOf("HH"))))) { if ((formatString.indexOf("mi") > 0) && (((formatString.indexOf("hh")) > 0 || (formatString.indexOf("HH"))))) { td.appendChild(spnColon.cloneNode(true)); } else { td.appendChild(spnColon); } } if (formatString.indexOf("ss") > 0) { td.appendChild(sltSecond); } tr.appendChild(td); tbody.appendChild(tr); tabFoot.appendChild(tbody); return tabFoot; }; Calendar.prototype.btnPrevYear_Click = function (sender, event) { this.previousYear(); this.onCalendar_Update(); this.update(); }; Calendar.prototype.btnPrevMonth_Click = function (sender, event) { this.previousMonth(); this.onCalendar_Update(); this.update(); }; Calendar.prototype.btnNextMonth_Click = function (sender, event) { this.nextMonth(); this.onCalendar_Update(); this.update(); }; Calendar.prototype.btnNextYear_Click = function (sender, event) { this.nextYear(); this.onCalendar_Update(); this.update(); }; Calendar.prototype.optSelectYear_Click = function (sender, event) { this.setYear(sender.innerHTML); this.onCalendar_Update(); this.update(); }; Calendar.prototype.optSelectMonth_Click = function (sender, event) { this.setMonth((Number(sender.innerHTML) - 1)); this.onCalendar_Update(); this.update(); }; Calendar.prototype.sltMoreYear_Click = function (sender, event) { var height = self.childNodes[1].offsetHeight; this.showMore(1900, 2100, height, Number(sender.innerHTML), "selectYear"); }; Calendar.prototype.sltMoreMonth_Click = function (sender, event) { var height = self.childNodes[1].offsetHeight; this.showMore(1, 12, height, Number(sender.innerHTML), "selectMonth"); }; Calendar.prototype.tdDay_DblClick = function (sender, event) { this.setDate(Number(sender.innerHTML)); this.calendar_DblClick(sender, event); }; Calendar.prototype.tdDay_Click = function (sender, event) { }; Calendar.prototype.btnMeridiem_Click = function (sender, event) { sender.innerHTML = (sender.innerHTML == 'AM' ? 'PM' : 'AM'); this.currMeridiem = sender.innerHTML; }; Calendar.prototype.optSelectHour_Click = function (sender, event) { this.setHour(Number(sender.innerHTML)); this.update(); }; Calendar.prototype.optSelectMinute_Click = function (sender, event) { this.setMinute(Number(sender.innerHTML)); this.update(); }; Calendar.prototype.optSelectSecond_Click = function (sender, event) { this.setSecond(Number(sender.innerHTML)); this.update(); }; Calendar.prototype.optSelect_OnMouseOver = function (sender, event) { sender.originClassName = sender.className; sender.className = "onMouseOver"; }; Calendar.prototype.optSelect_OnMouseOut = function (sender, event) { sender.className = sender.originClassName; }; Calendar.prototype.btnHour_Click = function (sender, event) { if (formatString.indexOf("HH") > 0) { this.showMore(0, 23, 70, Number(sender.innerHTML), "selectHour"); } else if (formatString.indexOf("hh") > 0) { this.showMore(1, 12, 70, Number(sender.innerHTML), "selectHour"); } }; Calendar.prototype.btnMinute_Click = function (sender, event) { this.showMore(0, 59, 70, Number(sender.innerHTML), "selectMinute"); }; Calendar.prototype.btnSecond_Click = function (sender, event) { this.showMore(0, 59, 70, Number(sender.innerHTML), "selectSecond"); }; Calendar.prototype.select_RollOver = function (sender, event) { sender.className = "selectRollOver"; }; Calendar.prototype.select_RollOut = function (sender, event) { sender.className = "selectRollOut"; }; Calendar.prototype.ctrlButton_RollOver = function (sender, event) { sender.className = "ctrlButtonRollOver"; }; Calendar.prototype.ctrlButton_RollOut = function (sender, event) { sender.className = "ctrlButtonRollOut"; }; Calendar.prototype.calendar_MouseEnter = function (sender, event) { }; Calendar.prototype.calendar_MouseOut = function (sender, event) { }; Calendar.prototype.calendar_DblClick = function (sender, event) { }; Calendar.prototype.getYear = function() { return this.currYear; } Calendar.prototype.getMonth = function() { return this.currMonth; } Calendar.prototype.getDate = function() { return this.currDate; } Calendar.prototype.setProperty = function(pro) { property = pro.split(", "); } Calendar.prototype.onCalendar_Update = function() { } this.showMore = function(starNum, endNum, height, selectedValue, method) { var object = window.event.srcElement; var selectedIndex = selectedValue - starNum; if(object.selectBox) { object.selectBox.selectedIndex = selectedIndex; object.selectBox.show(height); return; } var selectBox = window.document.createElement("div"); selectBox.className = "selectBox"; selectBox.style.top = window.event.clientY - window.event.offsetY + window.event.srcElement.offsetHeight - this.top; selectBox.style.left = window.event.clientX - object.offsetWidth - this.left; selectBox.show = showBox; selectBox.selectedIndex = selectedIndex; var table = window.document.createElement("table"); table.border = "0"; table.cellspacing = "0"; table.cellpadding = "0"; table.width = "100%"; var tbody = window.document.createElement("tbody"); for (var loop=starNum; loop<=endNum; loop++) { var tr = window.document.createElement("tr"); var td = window.document.createElement("td"); td.innerHTML = subZero(loop, 2); td.align = "center"; td.className = "unselect"; td.eventHandler = this; if (method == "selectYear") { td.onclick = function() { this.eventHandler.optSelectYear_Click(this, event); }; } else if (method == "selectMonth") { td.onclick = function() { this.eventHandler.optSelectMonth_Click(this, event); }; } else if (method == "selectHour") { td.onclick = function() { this.eventHandler.optSelectHour_Click(this, event); }; } else if (method == "selectMinute") { td.onclick = function() { this.eventHandler.optSelectMinute_Click(this, event); }; } else if (method == "selectSecond") { td.onclick = function() { this.eventHandler.optSelectSecond_Click(this, event); }; } td.onmouseover = function() { this.eventHandler.optSelect_OnMouseOver(this, event); }; td.onmouseout = function() { this.eventHandler.optSelect_OnMouseOut(this, event); }; tr.appendChild(td); tbody.appendChild(tr); } table.appendChild(tbody); selectBox.appendChild(table); self.appendChild(selectBox); object.selectBox = selectBox; object.selectBox.show(height); }; this.setFormatString = function(formatString) { formatString = formatString; } this.show = function(src) { self.style.width = this.width; self.style.height = this.height; self.style.top = this.top; self.style.left = this.left; this.display(); if (src != undefined) { this.format(src); }
this.update(); }; this.update = function() { while (self.childNodes.length > 0) { self.removeChild(self.childNodes(0)); }
self.appendChild(this.getHead(this.currYear, this.currMonth)); self.appendChild(this.getBody(this.currYear, this.currMonth)); self.appendChild(this.getFoot(this.currHour, this.currMinute, this.currSecond)); }; this.hide = function() { self.style.display = "none"; }; this.display = function() { self.style.display = "block"; }; this.nextMonth = function() { if (this.currMonth == 11) { this.currMonth = 0; this.currYear++; } else { this.currMonth++; } }; this.previousMonth = function() { if (this.currMonth == 0) { this.currMonth = 11; this.currYear--; } else { this.currMonth--; } }; this.setMonth = function(month) { this.currMonth = month; }; this.nextYear = function() { this.currYear++; }; this.previousYear = function() { this.currYear--; }; this.setYear = function(year) { this.currYear = year; }; this.setDate = function(date) { this.currDate = date; }; this.setHour = function(hour) { this.currHour = hour; }; this.setMinute = function(minute) { if (formatString.indexOf("HH") > 0) { this.currMinute = minute; } else if (formatString.indexOf("hh") > 0) { this.currMinute = this.currMeridiem == 'AM' ? minute : minute + 12; } }; this.setSecond = function(second) { this.currSecond = second; }; this.toString = function() { var returnString = formatString; returnString = returnString.replace("yyyy", this.currYear); returnString = returnString.replace("MM", subZero((this.currMonth + 1), 2)); returnString = returnString.replace("dd", subZero(this.currDate, 2)); returnString = returnString.replace("hh", subZero((this.currHour > 12 ? (this.currHour - 12) : this.currHour), 2)); returnString = returnString.replace("HH", subZero(this.currHour, 2)); returnString = returnString.replace("mi", subZero(this.currMinute, 2)); returnString = returnString.replace("ss", subZero(this.currSecond, 2)); returnString = returnString.replace("am", this.currMeridiem); return returnString; }; this.format = function(str) { try { var beginIndex = formatString.indexOf("yyyy"); if (beginIndex >= 0) { var year = Number(str.substring(beginIndex, (beginIndex + 4))); if (year == 'NaN' || year < 1900 || year > 2100) { throw new DateFormatException(); } this.currYear = year; } beginIndex = formatString.indexOf("MM"); if (beginIndex >= 0) { var month = Number(str.substring(beginIndex, (beginIndex + 2))) - 1; if (month == 'NaN' || month < 0 || month > 11) { throw new DateFormatException(); } this.currMonth = month; } beginIndex = formatString.indexOf("dd"); if (beginIndex >= 0) { var date = Number(str.substring(beginIndex, (beginIndex + 2))); if (date == 'NaN' || date < 1 || date > monthDays(this.currYear, this.currMonth)) { throw new DateFormatException(); } this.currDate = date; } beginIndex = formatString.indexOf("am"); if (beginIndex >= 0) { var meridiem = str.substring(beginIndex, (beginIndex + 2)); if (meridiem != "AM" && meridiem != "PM") { throw new DateFormatException(); } this.currMeridiem = meridiem; } beginIndex = formatString.indexOf("HH"); if (beginIndex >= 0) { var hour = Number(str.substring(beginIndex, (beginIndex + 2))); if (hour == 'NaN' || hour < 0 || hour > 23) { throw new DateFormatException(); } this.currHour = hour; } beginIndex = formatString.indexOf("hh"); if (beginIndex >= 0) { var hour = Number(str.substring(beginIndex, (beginIndex + 2))); if (hour == 'NaN' || hour < 0 || hour > 12) { throw new DateFormatException(); } this.currHour = this.currMeridiem == "AM" ? hour : hour + 12; } beginIndex = formatString.indexOf("mi"); if (beginIndex >= 0) { var minute = Number(str.substring(beginIndex, (beginIndex + 2))); if (minute == 'NaN' || minute < 0 || minute > 59) { throw new DateFormatException(); } this.currMinute = minute; } beginIndex = formatString.indexOf("ss"); if (beginIndex >= 0) { var second = Number(str.substring(beginIndex, (beginIndex + 2))); if (second == 'NaN' || second < 0 || second > 59) { throw new DateFormatException(); } this.currSecond = second; } } catch (dfe) { this.currYear = today.getYear(); this.currMonth = today.getMonth(); this.currDate = today.getDate(); this.currHour = today.getHours(); this.currMinute = today.getMinutes(); this.currSecond = today.getSeconds(); this.currMeridiem = (this.currHour >= 12 ? 'PM' : 'AM'); } }; function monthDays(year, month) { var days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if (month == 1) { return (((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))? 29: 28); } return days[month]; }; function firstDayOfWeek(year, month) { return ((new Date(year, month, 1)).getDay()); }; function showBox(iHeight) { var box = this; box.style.height = 1; box.style.display = "block"; window.clearInterval(box.timeHandle); box.timeHandle = window.setInterval(interValHandle, 1); var s = 0; var t = 1; function interValHandle() { box.scrollTop = 1000000; s = s + t * t; t += 0.5; box.style.height = parseInt(box.style.height) + Math.floor(s); box.style.width = (iHeight != 70 ? 50 : 35) / iHeight * box.offsetHeight; if( box.offsetHeight > iHeight ) { window.clearInterval(box.timeHandle); box.style.height = iHeight; var tbody = box.childNodes[0].childNodes[0] box.scrollTop = (tbody.childNodes[0].childNodes[0].offsetHeight + 2) * box.selectedIndex; tbody.childNodes[box.selectedIndex].childNodes[0].className = "selected"; window.document.attachEvent("onclick", box.hide = function() { box.style.display = "none"; window.document.detachEvent("onclick", box.hide); }); } } }; function subZero(str, digit) { str = str.toString(); for (var loop=str.length; loop<digit; loop++) { str = '0' + str; } return str; };}
function getDateString(formIndex, targetName, type) { var targetForm = document.forms[formIndex]; var target = targetForm[targetName]; if (target.calendar == null) { if (type == "long") { target.calendar = new Calendar("yyyy-MM-dd HH:mi"); } else if (type == "short") { target.calendar = new Calendar("yyyy-MM-dd"); } target.calendar.width = 250; target.calendar.height = 150; } if (type == "long") { target.calendar.setFormatString("yyyy-MM-dd HH:mi"); } else if (type == "short") { target.calendar.setFormatString("yyyy-MM-dd"); } target.calendar.left = window.event.clientX - target.calendar.offsetWidth > 600 ? 600 : window.event.clientX - target.calendar.offsetWidth; target.calendar.top = window.event.clientY - window.event.offsetY + window.event.srcElement.offsetHeight - target.offsetHeight; target.calendar.show(target.value); target.calendar.calendar_DblClick = function () { target.value = target.calendar.toString(); target.calendar.hide(); }; target.calendar.calendar_MouseEnter = function () { target.calendar.display(); }; target.calendar.calendar_MouseOut = function () { target.calendar.hide(); };}
Calendar.css:
.calendarBox { font-family: "ËÎÌå"; font-size: 12.5px; position: absolute; z-index: 1; background: #FFFFFF;}
.calendarBox td { font-family: "ËÎÌå"; font-size: 12.5px; background: #FFFFFF; border: none;}
.calendarBox .head .ctrlButton { font-family: Webdings; cursor: hand; border: #999999 solid 1px; color: #333333; background: #CCCCCC; width: 10%;}
.calendarBox .head .ctrlButtonRollOver { font-family: Webdings; cursor: hand; border: #999999 solid 1px; color: #FF6600; background: #CCCCCC; width: 10%;}
.calendarBox .head .ctrlButtonRollOut { font-family: Webdings; cursor: hand; border: #999999 solid 1px; color: #333333; background: #CCCCCC; width: 10%;}
.calendarBox .head .title { background: #FFFFFF; border: #CCCCCC dashed 1px; width: 60%;}
.calendarBox .select { cursor: hand; color: #000000;}
.calendarBox .selectRollOver { cursor: hand; color: #006699; font-weight: bold;}
.calendarBox .selectRollOut { cursor: hand; color: #000000;}
.calendarBox .selectBox { z-index: 2; cursor: hand; position: absolute; border: 1px solid #425E87; overflow-y: scroll; overflow-x: hidden; background-color: #FFFFFF; FILTER: progid:DXImageTransform.Microsoft.Shadow(Color=#999999, offX=10, offY=10, direction=120, Strength=5);}
.calendarBox .selectBox .unselect { font-weight: normal;}
.calendarBox .selectBox .selected { color: #003366; font-weight: bold;}
.calendarBox .selectBox .onMouseOver { font-weight: bold; color: #006699;}
.calendarBox .body td { cursor: pointer; border: #CCCCCC dashed 1px;}
.calendarBox .body #feast { color: #990000;}
.calendarBox .body .weekName td { font-weight: bold;}
.calendarBox .body .weekName .feast { color: #990000;}
调用方法:
<%@page import="java.text.SimpleDateFormat"%><%@page import="java.util.Date"%>
<%
Date today = new Date(); SimpleDateFormat sdfShort = new SimpleDateFormat("yyyy-MM-dd"); String startDate = request.getParameter("startDate"); if (startDate == null || startDate.equals("")) { Date start = null; if (today.getMonth() == 0) { start = new Date((today.getYear() - 1), 11, today.getDate()); } else { start = new Date(today.getYear(), (today.getMonth() - 1), today.getDate()); } startDate = sdfShort.format(start); } String endDate = request.getParameter("endDate"); if (endDate == null || endDate.equals("")) { endDate = sdfShort.format(today); }
Date start_date=sdfShort.parse(startDate); Date end_date=sdfShort.parse(endDate);%>
|
|
|
回复:日期js 软件技术
44(游客)发表评论于2007/2/1 15:14:53 |
|
» 1 »
|