时间戳201512250445在几分钟内更新

时间:2015-12-25 07:50:29

标签: javascript

我从sat24获得了卫星图像(气象卫星图像)的链接,但sat24不断更新时间戳UTC中的图像时间,例如:201512250445。我想添加一些代码,以获取时间戳UTC,但时间每15分钟更新一次,例如:201512250430201512250445,因为sat24在时间戳UTC每15分钟更新一次

我正在尝试,但我得到了未定义的时间

    var region = "" + 'sa' + "";
    var imageType = "" + 'visual5HDComplete' + "";
    var imageCount = 0 + 10 +0;
    var allowZoom = 'False' == 'True';
    var AmazonUrl = "" + '' + "";
    var satbeelden = 0 + 10 + 0;
        var expDate = new Date();

    var minutes = 480;
    expDate.setTime(expDate.getTime() + (minutes * 60 * 1000));
    //(this.refspot4 != null) $.fn.cookie("satrefspot4-v2", this.refspot4.toString(), { expires: expDate, path: '/' });
    var zoomX = 0;
    var zoomY = 0;
    var iszoom = false;


    var arrayImageTimes = [];
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");
    arrayImageTimes.push("" + minutes + "");

2 个答案:

答案 0 :(得分:0)

正常化:

var region = 'sa';
var imageType = 'visual5HDComplete';
var imageCount = 10;
var allowZoom = false;
var AmazonUrl = '';
var satbeelden = 10;
var expDate = new Date();

var quarter= 15*60*1000;
var currentTimeMillis = expDate.getTime();
var nearestQuarter =  Math.round(currentTimeMillis / quarter) * quarter;

var zoomX = 0;
var zoomY = 0;
var iszoom = false;

var arrayImageTimes = [];
for ( var n = 0; n < 10; n++ ) {
    arrayImageTimes.push(nearestQuarter);
    nearestQuarter += quarter;
}

这将为您提供自纪元以来以毫秒为单位存储的下十个完整季度的数组。

答案 1 :(得分:0)

此代码提醒当前日期时间,您希望看到的格式为15分钟:

var d = new Date();
var t = d.getTime();
d.setTime(t-t%(1000*60*15));
alert(f2(d));

function f(n) { return ('0'+n).slice(-2); };
function f2(d) {
    return d.getUTCFullYear()+f(d.getUTCMonth() + 1)+f(d.getUTCDate())+f(d.getUTCHours())+f(d.getUTCMinutes());
};

https://jsfiddle.net/ja81uLu8/