我有一个日期对象,其中包含我在我的剑道图表库中使用的一些日期值。
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承包商.. 我想用循环来做这件事,我想动态地计算。
答案 0 :(得分:2)
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');