zoukankan      html  css  js  c++  java
  • js 时间戳与日期之间的转换 随机字符串

     本文出自:https://www.cnblogs.com/2186009311CFF/p/14253131.html

    //timestamp时间戳
    const getTimestamp = () => {
        var timestamp = new Date().getTime(); //精确到毫秒
        return timestamp
    }
    
    //时间戳转化成时间
    const getTimesByTamp = (timestamp) => {
        var ttamp = timestamp;
        if (ttamp.length == 10) {
            ttamp = ttamp * 1000;
        }
        var date = new Date(ttamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = date.getDate() ;
        var h = date.getHours() ;
        var m = date.getMinutes();
        var s = date.getSeconds();
        if (D<10) {
            D='0'+D;
        }
        if (h<10) {
            h='0'+h;
        }
        if (m<10) {
            m='0'+m;
        }
        if (s<10) {
            s='0'+s;
        }
        
        return Y + M + D + ' '+ h + ':' + m + ':'+ s; ////2014-06-18 10:33:24
    }
    
    //nonce 生成八位随机数(含有大小写字母和数字)
    const getNonce = () => {
        return generateMixed(8);
    }
    
    const generateMixed = (n) => {
        // arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
        var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
            'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
        ];
        var res = "";
        for (var i = 0; i < n; i++) {
            var id = Math.ceil(Math.random() * 35);
            res += chars[id];
        }
        return res;
    }

     参考:https://zhuanlan.zhihu.com/p/101333398

  • 相关阅读:
    #writeup#pwnable unlink
    #pwnable#cmd2
    #writeup# 深交所CTF内训T2-上传漏洞
    #writeup# 深交所CTF内训T1-SQL注入
    HAProxy 基本翻译
    概况
    Day 2 @ RSA Conference Asia Pacific & Japan 2016
    Burp suite安装使用教程
    Windows server 2012 iis 网页HTTP 404.17
    SQL Server、MySQL、Oracle查询前n条记录
  • 原文地址:https://www.cnblogs.com/2186009311CFF/p/14253131.html
Copyright © 2011-2022 走看看