获取周数和周开始&使用引导日期选择器的结束日期 [英] Fetch week number and week start & end date using bootstrap datepicker

查看:103
本文介绍了获取周数和周开始&使用引导日期选择器的结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BootStrap DateTimePicker 是否有任何选项可用于获取星期数以及星期的开始和结束日期从日历中.

BootStrap DateTimePicker is there any option available to fetch the week number and week start and end date from the calendar.

演示链接

$('#datetimepicker1').datetimepicker({
  format: 'DD/MM/YYYY',    
  calendarWeeks:true
});

类似于HTML5的 week 属性

Something similar to the HTML5 week attribute

<input type="week"/>

推荐答案

我将依靠时间来提供所需的数据,特别是星期几"和格式"功能

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/

请参阅此小提琴中的示例,以帮助您入门 http://jsfiddle.net/spasticdonkey/9Lnbp7pw/3/

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.

这篇关于获取周数和周开始&amp;使用引导日期选择器的结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆