JS获取当前时间作为订单编号

需要获取的时间格式为:20190109174520

格式化时间的工厂函数如下


CurentTime()
    {
        let now = new Date();
        let year = now.getFullYear();       //年
        let month = now.getMonth() + 1;     //月
        let day = now.getDate();            //日
        let hh = now.getHours();            //时
        let mm = now.getMinutes();          //分
        let ss = now.getSeconds();           //秒
        let clock = year + "";
        if(month < 10)
            clock += "0";

        clock += month + "";

        if(day < 10)
            clock += "0";

        clock += day + "";

        if(hh < 10)
            clock += "0";

        clock += hh + "";
        if(mm < 10) clock += '0';
        clock += mm + "";

        if(ss < 10) clock += '0';
        clock += ss;
        return(clock);
    }

使用时直接调用

this.CurentTime()

 

posted @ 2019-01-09 17:48  一捆铁树枝_james  阅读(111)  评论(0)    收藏  举报