使用bootstrap-datepicker在日期之后显示星期几 [英] Display Day of the Week after Date with bootstrap-datepicker
本文介绍了使用bootstrap-datepicker在日期之后显示星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 bootstrap-datepicker ,并且还要在日期之后的文本字段中显示实际的星期几.
I'm using bootstrap-datepicker and would like to also display the actual day of the week in the text field right after the date.
示例:12/01/2014 Monday
我的日期选择器配置
$(document).ready(function () {
$('#calendar').datepicker({
format: "mm/dd/yyyy",
weekStart: 1,
autoclose: true,
todayHighlight: true,
});
});
实际的日期选择器来源在这里:
The actual datepicker source is here:
https://bootstrap-datepicker.readthedocs.org/
推荐答案
您可以尝试执行以下操作,仅将此部分添加到您的代码中:
You can try something like this, only add this part to your code:
$('#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);
});
希望对你有用.
这篇关于使用bootstrap-datepicker在日期之后显示星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文