日历和时间的获取

<input type="text" name="end_time" id="today">
function today() {//构建方法
    var today = new Date();//new 出当前时间
    var h = today.getFullYear();//获取年
    var m = today.getMonth() + 1;//获取月
    var d = today.getDate();//获取日
    var H = today.getHours();//获取时
    // var M = today.getMinutes();//获取分
    // var S = today.getSe
    // conds();//获取秒
    return h + "-" + m + "-" + d + " " + H; //返回 年-月-日 时:分:秒
}

document.getElementById("today").value = today();//将获取到的 年-月-日 时:分:秒 赋给input文本输入框


    var input = document.getElementById('today');

    console.log(input.value)

 

laydate 使用方法

<input type="text" class="demo-input" placeholder="时间选择器" id="test5">
lay('#version').html('-v' + laydate.v);

//  第一个日历
laydate.render({
    elem: '#test5'
    , type: 'datetime'
    , done: function (value, date, endDate) {
        alert(value); //得到日期生成的值,如:2017-08-18

    }
});

 

layui  UI框架中也可以运用日历插件

 

https://www.layui.com/doc/modules/laydate.html

 

具体的使用,看文档,调用中使用

 

获取本地时间

function hello() {
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "年";
        var seperator3 = '月';
        var seperator4 = '日';
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        // 月
        console.log(month);


        // 日
        var strDate = date.getDate();

        console.log(strDate);

        // 分钟

        var getMinute=date.getMinutes();

        console.log(getMinute);

        // 秒钟.getSeconds()

        var getSeconds=date.getSeconds();

        console.log(getSeconds);

        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }

        if (getMinute >= 0 && getMinute <= 9) {
            getMinute = "0" + getMinute;
        }

        if (getSeconds >= 0 && getSeconds <= 9) {
            getSeconds = "0" + getSeconds;
        }

        var currentdate = date.getFullYear() + seperator1
            + month + seperator3
            + strDate + seperator4 + " "
            + date.getHours() + seperator2
            + getMinute + seperator2
            + getSeconds;
        // return currentdate;

        console.log(currentdate)
    }

    var data = getNowFormatDate();

    // console.log(data);
    $('#banaea_div').html(data)
}
hello();








 function format(){
        var nowDate = new Date();
        var Y = nowDate.getFullYear();
        var M = nowDate.getMonth() + 1;
        M = M < 10 ? '0' + M : M;// 不够两位补充0
        var D = nowDate.getDate();
        D = D < 10 ? '0' + D : D;
        var H = nowDate.getHours();
        H = H < 10 ? '0' + H : H;
        var Mi = nowDate.getMinutes();
        Mi = Mi < 10 ? '0' + Mi : Mi;
        var S = nowDate.getSeconds();
        S = S < 10 ? '0' + S : S;
        return  currentdates= Y + '-' + M + '-' + D + ' ' + H + ':' + Mi + ':' + S;
    }


    format();
    console.log(currentdates)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值