JavaScripts 日期

在input框中设置日期

js

    $(function () {
        var myDate = new Date;
        var year = myDate.getFullYear().toString();//获取当前年
        var months = myDate.getMonth() + 1;//获取当前月


        var days = myDate.getDate().toString();//获取当前日
        if (months >= 1 && months <= 9) {
            months = "0" + months;
         };
         if (days >= 0 && days <= 9) {
             days = "0" + days;
         };
        var current_date = year + '-' + months.toString() + '-' + days
        $('.form_datetime').val(current_date)
        $(".form_datetime").datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            minView: "month",
            startDate: current_date
        });
    });

html

<div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">开始时间:</label>
                        <div class="col-sm-8">

                            <input type="text" name="serverid" value="年/月/日" class="form_datetime form-control"
                                   id="add_start_time">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">结束时间:</label>
                        <div class="col-sm-8">
                            <input type="text" name="serverid" value="年/月/日" class="form_datetime form-control"
                                   id="add_end_time">

                        </div>
                    </div>

 

posted @ 2018-07-12 15:06  AndRew-A  阅读(315)  评论(0编辑  收藏  举报