js日期转换

2021-03-03 23:26

阅读:594

标签:function   ons   div   substr   mon   bsp   ice   locale   转换   

1. 转换为:2020-7-9

var d = new Date()

    function date(date) {
        var nowdate = new Date(date).toLocaleDateString().replace(/\//g, ‘-‘)
        return nowdate
    }
    console.log(date(d));

2. 转换为2020/7/9

var d = new Date()

    function date(date) {
        var nowdate = new Date(date).toLocaleDateString()
        return nowdate
    }
    console.log(date(d));

3. 转换为2020-07-09 11:30:23

var d = new Date()

    function date(now) {
        // var now = new Date(),
        y = now.getFullYear(),
            m = ("0" + (now.getMonth() + 1)).slice(-2),
            d = ("0" + now.getDate()).slice(-2);
        return y + "-" + m + "-" + d + " " + now.toTimeString().substr(0, 8);
    }
    console.log(date(d));

 

js日期转换

标签:function   ons   div   substr   mon   bsp   ice   locale   转换   

原文地址:https://www.cnblogs.com/linliu/p/13272695.html


评论


亲,登录后才可以留言!