uuid&&yy-mm-dd

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>

    <body>
        <script type="text/javascript">
            var s = [];
            var hexDigits = "0123456789abcdef";
            for(var i = 0; i < 36; i++) {
                s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
            }
            s[14] = "4"; 
            s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); 
            s[8] = s[13] = s[18] = s[23] = "-";

            var uuid = s.join("");
            console.log(uuid)
            
            
//document.write(d.getFullYear())
            
                var date = new Date()
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? '0' + m : m;
                var d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                time_log = y + '-' + m + '-' + d;
            console.log(time_log) ;
            
            
        </script>
    </body>

</html>

uuid&&当前时间yy-mm-dd

上传图片到服务器时候用到的参数(记载一下)

时间戳转化为时间yy-mm-dd hh-mm-ss

    var date = new Date()
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? '0' + m : m;
                var d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                time_log = y + '-' + m + '-' + d;
            console.log(time_log);
            
function add0(m){return m<10?'0'+m:m }
function timeFormat(timestamp){

    var time = new Date(timestamp);
    var year = time.getFullYear();
    var month = time.getMonth()+1;
    var date = time.getDate();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();
    return year+'-'+add0(month)+'-'+add0(date)+' '+add0(hours)+':'+add0(minutes)+':'+add0(seconds);
}
console.log(timeFormat(1245445455454))

下面的代码是精确到毫秒的代码

var date = new Date()
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? '0' + m : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            
            h = date.getHours()
            h = h < 10 ? ('0' + h) : h;
            minutes = date.getMinutes()
            minutes = minutes < 10 ? ('0' + minutes) : minutes;
            s = date.getSeconds()
            s = s < 10 ? ('0' + s) : s;
            ms =date.getMilliseconds()
            if( 9<ms&& ms<100 ){
                ms = '0'+ms
            }else if(ms<10){
                ms = '00'+ms
            }
            time_log = y + '-' + m + '-' + d+ '-'+h+ '-'+minutes+ '-'+s+ '-'+ms
                console.log(time_log)

 https://www.jb51.net/article/146200.htm   这篇文章在element ui中使用table表格输出时间的方法。

posted @ 2018-12-19 17:41  山外已有山  阅读(374)  评论(0编辑  收藏  举报