Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript函数显示今天的约会/日期_Javascript_Html_Appointment - Fatal编程技术网

使用JavaScript函数显示今天的约会/日期

使用JavaScript函数显示今天的约会/日期,javascript,html,appointment,Javascript,Html,Appointment,我想在HTML中显示当天的实际约会。我想用JavaScript实现它,从excel表中获取约会的名称和日期。 我已经写了一些东西,但它不工作,而且不是我想要的方式。 代码: 功能预约(){ var事件=[]; var-temp=[]; 事件[0]=“17.12.2015”,“测试1”]; 事件[1]=[“11.12.2015”,“TestToday”]; var数据=新日期(); var today=today.getDate(); var month=today.getMonth()+1;

我想在HTML中显示当天的实际约会。我想用JavaScript实现它,从excel表中获取约会的名称和日期。 我已经写了一些东西,但它不工作,而且不是我想要的方式。 代码:

功能预约(){
var事件=[];
var-temp=[];
事件[0]=“17.12.2015”,“测试1”];
事件[1]=[“11.12.2015”,“TestToday”];
var数据=新日期();
var today=today.getDate();
var month=today.getMonth()+1;
对于(i=0;i0)?((温度[i]=(温度长度-1))?“和”:“,”::)+temp[event[1]][3]+”(“+temp[event[i]][2]+”);
}
书面文件(x2+任命);
}

}
问题在您的for循环中。要比较今天的日期,应采用数组中的
dd.mm.yy
格式:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!

var yyyy = today.getFullYear();
if(dd<10)
    dd='0'+dd;

if(mm<10)
    mm='0'+mm;

var today = dd+'.'+mm+'.'+yyyy;

for (i = 0; i < event.length; i++) {
    if (event[i]) {
        if (event[i][0] == today) {
            temp[i] = event[i][0];
        }
    }
    // Don't break your for loop

}
var today=新日期();
var dd=today.getDate();
var mm=today.getMonth()+1//一月是零!
var yyyy=today.getFullYear();
如果(dd将代码更改为

var datum = new Date().setHours(0,0,0,0);
//you don't need today and month
if (event[i]) {
   eventDate = new Date(event[i][0].split(".").reverse()).getTime();
   if (datum === eventDate) {
        temp.push(event[i][1]); //there was a problem here as well
   }
}
else {
   break;
}