bootstrap-datetimepicker

<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="../Content/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<link href="../Content/bootstrap-select.min.css" rel="stylesheet" />

<!-- ÒýÈëbootstrapÑùʽ -->
<link href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- ÒýÈëbootstrap-tableÑùʽ -->
<link href="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.css" rel="stylesheet">

<!-- jquery -->
<script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
<!--时间控件-->
<script src="../Scripts/bootstrap-datetimepicker.min.js"></script>
<script src="../Scripts/bootstrap-select.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- bootstrap-table.min.js -->
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>
<!-- ÒýÈëÖÐÎÄÓïÑÔ°ü -->
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
//  转化时间格式
   // 转时间格式
    function changeDateFormat(cellval) {
        var dateVal = cellval + "";
        if (cellval != null) {
            var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

            var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
            var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

            return date.getFullYear() + "-" + month + "-" + currentDate;//+ " " + hours + ":" + minutes + ":" + seconds;
        }
    }
$('#birthdayDate').datetimepicker({
        language: 'zh-CN',//显示中文
        format: 'yyyy-mm-dd',//显示格式
        minView: "month",//设置只显示到月份
        initialDate: new Date(),
        autoclose: true,//选中自动关闭
        todayBtn: true,//显示今日按钮
        //locale: moment.locale('zh-cn')
    });
//  赋值 时间为当前时间


 //默认获取当前日期
    var today = new Date();
    var nowdate = (today.getFullYear()) + "-" + (today.getMonth() + 1) + "-" + today.getDate();
    //对日期格式进行处理
    var date = new Date(nowdate);
    var mon = date.getMonth() + 1;
    var day = date.getDate();
    var mydate = date.getFullYear() + "-" + (mon < 10 ? "0" + mon : mon) + "-" + (day < 10 ? "0" + day : day);
    //日期时间控件默认值的设置,需要注意的是,在JS中使用的ID是input标签的ID。
    document.getElementById("inbirthdayDate").value = mydate;
使用方法


  <a class='input-group date' id='birthdayDate'>
                        <input type='text' class="form-control" id='inbirthdayDate' style="width: 150px; height: 30px;" />
                        <span class="input-group-addon" style="float: left; width: 50px; height: 30px;">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </a>

 

posted @ 2018-08-21 13:05  谁说程序猿很猥琐  阅读(549)  评论(0编辑  收藏  举报