js 时间戳与日期之间的转换 随机字符串
2021-03-03 17:26
标签:tno lan 字符串 时间 logs target log targe 字符 本文出自:https://www.cnblogs.com/2186009311CFF/p/14253131.html 参考:https://zhuanlan.zhihu.com/p/101333398 js 时间戳与日期之间的转换 随机字符串 标签:tno lan 字符串 时间 logs target log targe 字符 原文地址: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 ;
var D = date.getDate() ;
var h = date.getHours() ;
var m = date.getMinutes();
var s = date.getSeconds();
if (D) {
D=‘0‘+D;
}
if (h) {
h=‘0‘+h;
}
if (m) {
m=‘0‘+m;
}
if (s) {
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 ) {
var id = Math.ceil(Math.random() * 35);
res += chars[id];
}
return res;
}
上一篇:jsDOM批量插入节点性能测试
下一篇:HTTP和HTTPS
文章标题:js 时间戳与日期之间的转换 随机字符串
文章链接:http://soscw.com/index.php/essay/59605.html