首页 > 解决方案 > 推送数组momentJS小时UTC

问题描述

我正在使用 moment.js 来格式化 hours 。我想每 6 小时获取一次数组。

预期成果小时数发布

[6,12,24,36,48];

运行代码后的输出

    [6,12,6,12,6];

代码 :

    let date = moment();
    this.hours = []

        for (let i = 0 i <= 4; i++) {
           
            this.hours.push(date.add(6,"hour").format("h"))
        }

请问有什么解决办法吗?

标签: typescriptmomentjs

解决方案


// let date = moment();
this.hours = []

    for (let i = 0 i <= 4; i++) {
       if(i === 0)this.hours.push(6);
       this.hours.push(12*i);
        //this.hours.push(date.add(6,"hour").format("h"))
    }

推荐阅读