Javascript获取范围内每个工作日的MM/DD值?
下面的javascript代码创建了一个每周日历,它为我提供开始日期和结束日期:Javascript获取范围内每个工作日的MM/DD值?,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,下面的javascript代码创建了一个每周日历,它为我提供开始日期和结束日期: 我如何调整它,使其同时给出范围内每个工作日的MM/DD值 例如,我需要将以下变量输出到我的表单中: var startDate;(ex..11/10/2013) var结束日期;(ex..11/16/2013) var圣代;(需要..11/10) 蒙代特变种;(需要..11/11) 杜瓦特;(需要..11/12) 威德塔特;(需要..11/13) 苏丹特变种;(需要..11/14) friDate变种;(需要.
- 我如何调整它,使其同时给出范围内每个工作日的MM/DD值
- 例如,我需要将以下变量输出到我的表单中:
- var startDate;(ex..11/10/2013)
- var结束日期;(ex..11/16/2013)
- var圣代;(需要..11/10)
- 蒙代特变种;(需要..11/11)
- 杜瓦特;(需要..11/12)
- 威德塔特;(需要..11/13)
- 苏丹特变种;(需要..11/14)
- friDate变种;(需要..11/15)
- var Sattate;(需要..11/16)
$(函数(){
var startDate;
var结束日期;
蒙代特变种;
杜瓦特;
威德塔特;
苏丹特变种;
friDate变种;
var Sattate;
var圣代;
var selectCurrentWeek=函数(){
setTimeout(函数(){
$('.week picker').find('.ui datepicker当前日期a').addClass('ui-state-active'))
}, 1);
}
$('.week picker')。日期选择器({
showOtherMonths:是的,
选择OtherMonths:true,
日期格式:“mm/dd”,
第一天:1,//从星期一开始
onSelect:function(dateText,inst){
var date=$(this.datepicker('getDate');
startDate=新日期(Date.getFullYear()、Date.getMonth()、Date.getDate()-Date.getDay()+1);
endDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+7);
monDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+1);
tueDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+2);
wedDate=新日期(Date.getFullYear()、Date.getMonth()、Date.getDate()-Date.getDay()+3);
thuDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+4);
friDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+5);
satDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+6);
sunDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay()+7);
var dateFormat=inst.settings.dateFormat | |$.datepicker._defaults.dateFormat;
$('#startDate').val($.datepicker.formatDate(dateFormat,startDate,inst.settings));
$('#endDate').val($.datepicker.formatDate(dateFormat,endDate,inst.settings));
$('#monDate').val($.datepicker.formatDate(dateFormat,monDate,inst.settings));
$('#tueDate').val($.datepicker.formatDate(dateFormat,tueDate,inst.settings));
$('#wedDate').val($.datepicker.formatDate(dateFormat,wedDate,inst.settings));
$('#thuDate').val($.datepicker.formatDate(dateFormat,thuDate,inst.settings));
$('#friDate').val($.datepicker.formatDate(dateFormat,friDate,inst.settings));
$('#satDate').val($.datepicker.formatDate(dateFormat,satDate,inst.settings));
$('sunDate').val($.datepicker.formatDate(dateFormat,sunDate,inst.settings));
选择CurrentWeek();
},
beforeShowDay:功能(日期){
var cssClass='';
如果(date>=startDate&&date那么……你可以找到一个库来帮助你,或者你可以自己编写。幸运的是,对你来说,这就是我所做的。我知道这不是一个代码编写服务,但我一直坐着不做任何事情
我在日期原型中添加了addSeconds(seconds)
,subtractSeconds(seconds)
,以及format(some_format)
。format函数使用的格式与MySQL完全相同
示例…从中的startDate开始
var startDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay());
对于(var x=1;x嗯……你可以找到一个库来帮助你,或者你可以自己编写。幸运的是,对你来说,这就是我所做的。我知道这不是一个代码编写服务,但我一直坐在那里什么都不做
我在日期原型中添加了addSeconds(seconds)
,subtractSeconds(seconds)
,以及format(some_format)
。format函数使用的格式与MySQL完全相同
示例…从中的startDate开始
var startDate=新日期(Date.getFullYear(),Date.getMonth(),Date.getDate()-Date.getDay());
对于(var x=1;x来自手册:
在代码中:
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "dd/mm",
您的代码看起来不错,但只有在第一天为1时才有效,更新代码以使用您提供的html
$(function() {
//removed all variables
var selectCurrentWeek = function() {
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a')
.addClass('ui-state-active')
}, 1);
}
//changed this function
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "mm/dd",
firstDay: 1, // Start with Monday
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate'),
start = inst.settings.firstDay || $.datepicker._defaults.firstDay,
year = date.getFullYear(),month = date.getMonth(),
day = (date.getDate()-date.getDay()),
elIds=["#monDate","#tueDate","#wedDate","#thuDate","#friDate","#satDate",
"#sunDate","#startDate","#endDate"],
i=-1,start,dates=[],
dateFormat = inst.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
day=(date.getDay()<start)?(day+start)-7:day+start;
while(++i<7){
dates.push(new Date(year,month,day+i));
$(elIds[i]).val($.datepicker.formatDate( dateFormat, dates[i]
, inst.settings ));
}
i=-1;
$(elIds[7]).val($.datepicker.formatDate( dateFormat, dates[0],
inst.settings ));
$(elIds[8]).val($.datepicker.formatDate( dateFormat, dates[6],
inst.settings ));
selectCurrentWeek();
},
});
$('.week-picker .ui-datepicker-calendar tr').on('mousemove', function() {
$(this).find('td a').addClass('ui-state-hover');
});
$('.week-picker .ui-datepicker-calendar tr').on('mouseleave', function() {
$(this).find('td a').removeClass('ui-state-hover');
});
});
$(函数(){
//删除所有变量
var selectCurrentWeek=函数(){
setTimeout(函数(){
$(“.week picker”).find(“.ui datepicker当前日期a”)
.addClass('ui-state-active')
}, 1);
}
//更改了此功能
$('.week picker')。日期选择器({
showOtherMonths:是的,
选择OtherMonths:true,
日期格式:“mm/dd”,
第一天:1,//从星期一开始
onSelect:function(dateText,inst){
var date=$(this).datepicker('getDate'),
start=inst.settings.firstDay | |$.datepicker.\u defaults.firstDay,
年=日期。getFullYear(),月=日期。getMonth(),
day=(date.getDate()-date.getDay()),
elIds=[“#monDate”、“#tueDate”、“#wedDate”、“#thuDate”、“#friDate”、“#satDate”,
“圣代”、“开始日期”、“结束日期”],
i=-1,开始,日期=[],
dateFormat=inst.settings.dateFormat | |
$.datepicker.\u defaults.dateFormat,
day=(手册中的date.getDay():
在代码中:
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "dd/mm",
您的代码看起来不错,但只有在第一天为1时才有效,更新代码以使用您提供的html
$(function() {
//removed all variables
var selectCurrentWeek = function() {
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a')
.addClass('ui-state-active')
}, 1);
}
//changed this function
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "mm/dd",
firstDay: 1, // Start with Monday
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate'),
start = inst.settings.firstDay || $.datepicker._defaults.firstDay,
year = date.getFullYear(),month = date.getMonth(),
day = (date.getDate()-date.getDay()),
elIds=["#monDate","#tueDate","#wedDate","#thuDate","#friDate","#satDate",
"#sunDate","#startDate","#endDate"],
i=-1,start,dates=[],
dateFormat = inst.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
day=(date.getDay()<start)?(day+start)-7:day+start;
while(++i<7){
dates.push(new Date(year,month,day+i));
$(elIds[i]).val($.datepicker.formatDate( dateFormat, dates[i]
, inst.settings ));
}
i=-1;
$(elIds[7]).val($.datepicker.formatDate( dateFormat, dates[0],
inst.settings ));
$(elIds[8]).val($.datepicker.formatDate( dateFormat, dates[6],
inst.settings ));
selectCurrentWeek();
},
});
$('.week-picker .ui-datepicker-calendar tr').on('mousemove', function() {
$(this).find('td a').addClass('ui-state-hover');
});
$('.week-picker .ui-datepicker-calendar tr').on('mouseleave', function() {
$(this).find('td a').removeClass('ui-state-hover');
});
});
$(函数(){
//删除所有变量
var selectCurrentWeek=函数(){
设置超时(f
/**
* Add a number of seconds to the current date
* @return Date The date object
*/
Date.prototype.addSeconds = function(seconds) {
var time = this.getTime();
alert("time = " + time);
time += seconds * 1000;
this.setTime(time);
return this;
}
/**
* Subtract a number of seconds to the current date
* @return Date The date object
*/
Date.prototype.subtractSeconds = function(seconds) {
var time = this.getTime();
alert("time = " + time);
time -= seconds * 1000;
this.setTime(Math.max(0, time));
return this;
}
/**
* DATE
* format() - uses MySQL date formatting... a few of the more obscure formats are left unfinished
*/
Date.prototype.format = function(format) {
var short_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var short_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var escaped = false;
var pieces = new Array();
for (var x = 0; x < format.length; ++x) {
if (!escaped) {
if (format.charAt(x) != "%") {
pieces.push(format.charAt(x));
} else {
escaped = true;
}
continue;
}
switch (format.charAt(x)) {
case "a":
pieces.push(short_days[this.getDay()]); break;
case "b":
pieces.push(short_months[this.getMonth()]); break;
case "c":
pieces.push(Number(this.getMonth()) + 1); break;
case "D":
pieces.push(this.getDate()); break;
case "d":
var day_of_month = new String(this.getDate());
pieces.push(day_of_month.pad(2, "0")); break;
case "e":
pieces.push(this.getDate()); break;
case "f":
var microseconds = new String(this.getMilliseconds() * 1000);
pieces.push(microseconds.pad(6, "0")); break;
case "H":
pieces.push(this.getHours()); break;
case "h":
var hours = this.getHours() % 12;
hours = (hours == 0) ? "12" : new String(hours);
pieces.push(hours.pad(2, "0")); break;
case "I":
var hours = this.getHours() % 12;
hours = (hours == 0) ? "12" : new String(hours);
pieces.push(hours.pad(2, "0")); break;
case "i":
var minutes = new String(this.getMinutes());
pieces.push(minutes.pad(2, "0")); break;
case "j": // day of the year 001...365
pieces.push("???"); break;
case "k":
pieces.push(this.getHours()); break;
case "l":
var hours = this.getHours() % 12;
pieces.push((hours == 0) ? "12" : hours); break;
case "M":
pieces.push(months[this.getMonth()]); break;
case "m":
var month = new String(Number(this.getMonth()) + 1);
pieces.push(month.pad(2, "0")); break;
case "p":
pieces.push((this.getHours() < 12) ? "AM" : "PM"); break;
case "r": // 12-hour hh:mm:ss AM/PM
pieces.push("?"); break;
case "S": case "s":
pieces.push(this.getSeconds()); break;
case "T": // 24-hour hh:mm:ss
pieces.push("?"); break;
case "u": case "U":
case "v": case "V":
pieces.push("?"); break;
case "W":
pieces.push(days[this.getDay()]); break;
case "w":
pieces.push(this.getDay()); break;
case "x": case "X": // year for the week w/sunday or monday starting???
pieces.push("?"); break;
case "Y":
pieces.push(this.getFullYear()); break;
case "y":
var full_year = new String(this.getFullYear());
pieces.push(full_year.substr(2, 2)); break;
default:
pieces.push(format.charAt(x)); break;
}
escaped = false;
}
return pieces.join("");
}
$( ".selector" ).datepicker({ dateFormat: "yy-mm-dd" });
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "dd/mm",
$(function() {
//removed all variables
var selectCurrentWeek = function() {
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a')
.addClass('ui-state-active')
}, 1);
}
//changed this function
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "mm/dd",
firstDay: 1, // Start with Monday
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate'),
start = inst.settings.firstDay || $.datepicker._defaults.firstDay,
year = date.getFullYear(),month = date.getMonth(),
day = (date.getDate()-date.getDay()),
elIds=["#monDate","#tueDate","#wedDate","#thuDate","#friDate","#satDate",
"#sunDate","#startDate","#endDate"],
i=-1,start,dates=[],
dateFormat = inst.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
day=(date.getDay()<start)?(day+start)-7:day+start;
while(++i<7){
dates.push(new Date(year,month,day+i));
$(elIds[i]).val($.datepicker.formatDate( dateFormat, dates[i]
, inst.settings ));
}
i=-1;
$(elIds[7]).val($.datepicker.formatDate( dateFormat, dates[0],
inst.settings ));
$(elIds[8]).val($.datepicker.formatDate( dateFormat, dates[6],
inst.settings ));
selectCurrentWeek();
},
});
$('.week-picker .ui-datepicker-calendar tr').on('mousemove', function() {
$(this).find('td a').addClass('ui-state-hover');
});
$('.week-picker .ui-datepicker-calendar tr').on('mouseleave', function() {
$(this).find('td a').removeClass('ui-state-hover');
});
});