gpt4 book ai didi

javascript - 不同时间重复物体

转载 作者:行者123 更新时间:2023-12-02 16:40:24 25 4
gpt4 key购买 nike

我有一个日期对象,其中包含我在剑道图表库中使用的一些日期值。

var dataF = [{
//"date": new Date("2014/11/26 00:00:00")
"date": new Date(dateSelectedPopupJson + " 00:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 01:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 02:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 03:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 04:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 05:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 06:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 07:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 08:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 09:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 10:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 11:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 12:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 13:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 14:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 15:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 16:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 17:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 18:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 19:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 20:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 21:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 22:00:00")
}, {
"date": new Date(dateSelectedPopupJson + " 23:00:00")
}];

同一个对象具有 24 小时时间数据,您可以看到小时时间正在增加..

喜欢

"2014/11/26 00:00:00

"2014/11/26 01:00:00


"2014/11/26 02:00:00

在我的代码中,我对该值进行硬编码。我有 dateF,它有 24 个不同时间的对象..

我不想要这个静态 json 承包商..我想使用循环来做到这一点,并且我想动态计算。

最佳答案

function makeDates(dateSelectedPopupJson) {
var dates = [];
for(i = 0 ; i < 24 ; i++) {
dates.push({
"date" : new Date(dateSelectedPopupJson + " " + i + ":00:00")
});
}
return dates;
}

var dataF = makeDates('2014/11/26');

关于javascript - 不同时间重复物体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27560305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com