获取日期范围内的epoch时间戳列表

Get a list of epoch timestamps in a date range?

本文关键字:时间戳 列表 epoch 取日期 范围内 获取      更新时间:2023-09-26

在一个web应用程序上工作。我还没有来自web服务的数据,但我知道数据将包括一个epoch时间戳。我想知道是否有人知道一种方法来生成连续(随机)纪元时间戳。我使用freedatgenerator来满足我的大多数数据生成需求,它们有创建epoch时间戳的方法,但不是按顺序创建的。我需要数百个用于测试目的,所以我真的不想手工操作。

如何创建一个连续的顺序?

var myDates = [Math.floor(Date.now() / 1000)]; //UTC timestamp in seconds
var maxGap = 60; //our maximum time gap is 60 seconds
for(var i = 0; i<100; i++) {
    myDates.push(myDates[i] + Math.floor((Math.random() * maxGap) + 1));
}
//myDates now contains random consecutive integer timestamps in seconds