我正在使用 bootstrap-datepicker ,并希望在日期之后的文本字段中显示一周中的实际星期几。
示例:12/01/2014 Monday
我的日期拣货配置
$(document).ready(function () {
$('#calendar').datepicker({
format: "mm/dd/yyyy",
weekStart: 1,
autoclose: true,
todayHighlight: true,
});
});
实际的datepicker源位于:
答案 0 :(得分:4)
您可以尝试这样的方法,只将此部分添加到您的代码中:
$('#calendar').change(function () { //Your date picker input
var eventDate = $('#calendar').val();
var dateElement = eventDate.split("/");
var dateFormat = dateElement[2]+'-'+dateElement[0]+'-'+dateElement[1];
var date = new Date(dateFormat+'T10:00:00Z'); //To avoid timezone issues
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var day = weekday[date.getDay()];
$('#calendar').val($('#calendar').val() + ' ' + day);
});
希望对你有用。
答案 1 :(得分:4)
改变一件事
format: "mm/dd/yyyy DD"
http://bootstrap-datepicker.readthedocs.io/en/latest/options.html#format
答案 2 :(得分:0)
以下代码有效:
$('#CalenderInputTextBox').change(function (e) {
var eventDate = $('#CalenderInputTextBox').val();
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var date = new Date(eventDate).getDay();
var day = weekday[date];
$('#CalenderInputTextBox').val($('#CalenderInputTextBox').val() + ' ' + day);
});