问题
BootStrap DateTimePicker is there any option available to fetch the week number and week start and end date from the calendar.
Demo link
$('#datetimepicker1').datetimepicker({
format: 'DD/MM/YYYY',
calendarWeeks:true
});
Something similar to the HTML5 week attribute
<input type="week"/>
回答1:
I would rely on moment to provide the data you are looking for, specifically the Day of Week and Format functions
http://momentjs.com/docs/#/get-set/day/
http://momentjs.com/docs/#/displaying/format/
See this fiddle for examples to get you started http://jsfiddle.net/spasticdonkey/9Lnbp7pw/3/
$('#datetimepicker1').on('dp.change', function (e) {
var kk = $("#datepicker").val();
$("#output").html(
"Week Number: " + moment(kk, "DD/MM/YYYY").week() + " of " +
moment(kk, "DD/MM/YYYY").weeksInYear()
);
$("#output2").html(
"Day of Year: " + moment(kk, "DD/MM/YYYY").dayOfYear()
);
$("#output3").html(
"Day of Week: " + moment(kk, "DD/MM/YYYY").day() + " of 6 (" +
moment(kk, "DD/MM/YYYY").format("dddd") + ")"
);
$("#output4").html(
"Start of Week: " + moment(kk, "DD/MM/YYYY").day(0).format("DD/MM/YYYY")
);
$("#output5").html(
"End of Week: " + moment(kk, "DD/MM/YYYY").day(6).format("DD/MM/YYYY")
);
});
Note that there are differences, depending on locale, which day is considered the first day of the week. If you are attempting to support multiple locales you will need to dig deeper into the moment documentation regarding locale aware dates.
来源:https://stackoverflow.com/questions/30230615/fetch-week-number-and-week-start-end-date-using-bootstrap-datepicker