[英]Compare date in JS
I have js function 我有js功能
function getDriving() {
markers.length = 0;
var todayval = new Date();
var newtodaydata = new Date(todayval.toDateString());
console.log(newtodaydata);
var url = $('#map').data('request-url2');
$.getJSON(url,
function (data) {
$.each(data,
function (i, item) {
markers.push({
'location': new google.maps.LatLng(item.Latitude, item.Longitude),
'map': map,
'weight': item.Speed,
'radius': 10,
'date': item.CurrentDateTime,
'imei': item.Imei
});
});
var todaymarkersfiltered = markers.filter(function (marker) {
var getDate = marker.date.match(/\d/g).join('');
var markerDate = new Date(parseFloat(getDate));
console.log(markerDate);
return (markerDate === todayval);
});
var pointArray = new google.maps.MVCArray(todaymarkersfiltered);
console.log(pointArray);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
});
}; };
Here is what i have for var newtodaydata = new Date(todayval.toDateString());
这是我为
var newtodaydata = new Date(todayval.toDateString());
Thu Jan 25 2018 00:00:00 GMT+0200 (FLE Standard Time)
2018年1月25日星期四00:00:00 GMT + 0200(FLE标准时间)
And in console.log(markerDate);
并在
console.log(markerDate);
I have 2 markers with same data 我有2个标记的数据相同
But in todaymarkersfiltered
I have no markers. 但是在
todaymarkersfiltered
, todaymarkersfiltered
我没有标记。
Where is my problem? 我的问题在哪里?
Thank's for help. 感谢帮助。
I found my problem, I rewrite condition ===
to ==
我发现了问题,我将条件
===
重写为==
And make it like this markerDate.toDateString() == todayval.toDateString()
并使其像这个
markerDate.toDateString() == todayval.toDateString()
I rewrite code like this 我这样重写代码
function getDriving() {
markers.length = 0;
var todayval = new Date();
var url = $('#map').data('request-url2');
$.getJSON(url,
function (data) {
$.each(data,
function (i, item) {
markers.push({
'location': new google.maps.LatLng(item.Latitude, item.Longitude),
'map': map,
'weight': item.Speed,
'radius': 10,
'date': item.CurrentDateTime,
'imei': item.Imei
});
});
var todaymarkersfiltered = markers.filter(function (marker) {
var getDate = marker.date.match(/\d/g).join('');
var markerDate = new Date(parseFloat(getDate));
return (markerDate.toDateString() == todayval.toDateString());
});
var pointArray = new google.maps.MVCArray(todaymarkersfiltered);
console.log(pointArray);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
});
};
And now all okay 现在一切都好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.