dateTimepicker 设置默认日期的方法

1、属性初始化设置

 $('#beginDate').datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            weekStart: 1,
            todayBtn: false,
            autoclose: true,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            startDate:new Date()
        });

2、通过function函数计算日期之后赋值

 $('#beginDate').datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            weekStart: 1,
            todayBtn: false,
            autoclose: true,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            startDate:getDay(4,'-')
        });
       
        //正数为后一天,负数为前一天,str为日期间隔符,例如 -,/ 
        function getDay(num, str) {
            var today = new Date();
            var nowTime = today.getTime();
            var ms = 24 * 3600 * 1000 * num;
            today.setTime(parseInt(nowTime + ms));
            var oYear = today.getFullYear();
            var oMoth = (today.getMonth() + 1).toString();
            if (oMoth.length <= 1)
                oMoth = '0' + oMoth;
            var oDay = today.getDate().toString();
            if (oDay.length <= 1)
                oDay = '0' + oDay;
            return oYear + str + oMoth + str + oDay;
        }
posted @ 2019-06-03 17:16  麦田里的稻草人  阅读(...)  评论(...编辑  收藏