typescript - 推送数组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"))
}
请问有什么解决办法吗?
解决方案
// 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"))
}
推荐阅读
- html - 仅在 div 区域内禁用可点击元素
- python - 连接忙于另一个命令的结果,而正在使用 MARS 连接
- c# - 使用 Momo 频繁使用 SIGABRT 使控制台崩溃
- java - Appium 选择了错误的定位器
- php - 仅在一行中的条件下对对象调用 PHP 函数
- asp.net-mvc - 在 IIS8 中部署后,ASP.NET 对象引用未设置为对象的实例 - 组角色编辑中的空异常
- c# - Xamarin Android UnitTest 和 Instrumentation 测试(不是表单)
- three.js - three.js - 如何高效地生成星星
- reactjs - 在每次页面加载时反应刷新用户数据
- c# - 闯入foreach后如何退出try块