console.log(Math.random().toString(36).substr(2, 15));
console.log(parseInt(new Date().getTime() / 1000));

本文介绍了一种使用JavaScript生成随机字符串的方法,并展示了如何获取当前时间的时间戳。通过Math.random()函数结合toString()和substr()方法,可以生成指定长度的随机字符串。同时,利用new Date().getTime()和parseInt()函数,可以得到精确到秒的时间戳。
console.log(Math.random().toString(36).substr(2, 15));
console.log(parseInt(new Date().getTime() / 1000));

1049
483
964

被折叠的 条评论
为什么被折叠?