Juan Carlos Oropeza Juan Carlos Oropeza - 1 year ago 71
Javascript Question

What datatype for date is using js

Im getting car object from my Web 2 api. I create my object so can be add on the map, and include some properties.

is type

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

But when check the value for the feature I get:

enter image description here

Im creating the info for the object, and want format the date in a readable format. What can I do?

Answer Source

In JS dates are shown as timestamps. To make them readable you can use the following code:

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();

Don't forget to upvote if you find this helpful!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download