Javascript 随机位置数组-矩-timezone.js
我如何根据数据找到随机位置?我想在每次刷新页面时显示一个新位置 当前代码:Javascript 随机位置数组-矩-timezone.js,javascript,arrays,momentjs,moment-timezone,Javascript,Arrays,Momentjs,Moment Timezone,我如何根据数据找到随机位置?我想在每次刷新页面时显示一个新位置 当前代码: <hero> <div id="hover"> <h2>Present time</h2> <div id="time"></div> </div> </hero> <script> (function clock() { var now = moment().format(
<hero>
<div id="hover">
<h2>Present time</h2>
<div id="time"></div>
</div>
</hero>
<script>
(function clock() {
var now = moment().format('lll'); //local time
/*
I want many of these..
moment.tz("Europe/Berlin").format('lll');
*/
var time = document.getElementById('time');
time.innerHTML = now;
setInterval(clock, 1000);
})();
</script>
现在
(功能时钟){
var now=moment().format('lll');//本地时间
/*
我想要很多这样的。。
矩.tz(“欧洲/柏林”).格式(“lll”);
*/
var time=document.getElementById('time');
time.innerHTML=now;
设置间隔(时钟,1000);
})();
通过从所有时区中选取一个随机元素,可以获得一个随机时区
var all = moment.tz.names();
var randomTimeZone = all[Math.floor(Math.random()*all.length)];
// Use it in the code as
moment.tz(randomTimeZone).format('lll');
您可以从以下选项中选择随机时区:
const timezones=moment.tz.names();
const randTimezone=时区[Math.floor(Math.random()*timezones.length)];
const now=moment.tz(随机时区).format('lll');
编写(随机时区,
,现在)代码>
当前代码:谢谢!对不起,你介意把它写在垃圾桶里吗?我的js很差…:/