日期的什么数据类型正在使用 js

What datatype for date is using js

我正在从我的 Web 2 获取汽车对象 api。我创建了我的对象,因此可以添加到地图上,并包含一些属性。 DateTime 是类型 datetime

var iconFeature = new ol.Feature({
            geometry: new ol.geom.Point(ol.proj.transform([car.X, car.Y], 'EPSG:4326',
            'EPSG:3857')),
            RoadName: car.RoadName,
            Azimuth: car.Azimuth,
            DateTime: car.DateTime
        });

但是当检查特征的值时,我得到:

我正在为对象创建信息,并希望以可读格式设置日期格式。我能做什么?

图像中显示的对象中的日期时间字段包含时间戳值。

您可以使用 Date Javascript 对象将其转换为您需要的格式。您还可以执行获取第二天或下一个小时等操作。这完全取决于您的要求。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

在 JS 中,日期显示为时间戳。为了使它们可读,您可以使用以下代码:

var minDate= -62135578800000;
var date = 
       new Date(parseInt(iconFeature.DateTime.substr(6, iconFeature.DateTime.length - 8)));

return (date.toString() == new Date(minDate).toString()) 
       ? "" 
       : (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();

如果觉得有帮助,别忘了点个赞!!