Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 随机位置数组-矩-timezone.js_Javascript_Arrays_Momentjs_Moment Timezone - Fatal编程技术网

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很差…:/