AnsweredAssumed Answered

Convert date field to legible date

Question asked by MollyKFoley on Mar 26, 2018
Latest reply on Mar 26, 2018 by evtguy

I'm having trouble extracting the year from my date fields, mostly because it gets reformatted into that weird integer that doesn't look like a date. How do you get this type of integer to look like a date: 1518566400000

 

I tried using the Date constructor but I don't think I'm using it right (or maybe I can't use it for this purpose at all?). Date | API Reference | ArcGIS API for JavaScript 4.6 

 

My code queries features, and for each feature I want to extract the year from the observation date to put into a select HTML element (drop-down menu). This is the code I have:

 

//Get all the years in which data was collected
function getYears(response){
  var features = response.features;
  //Put date of each feature into an array
  var values = features.map(function(feature){
    var obsvDate = feature.attributes.ObsvDate; //this is the weird integer
    //Do something here to change the date to a legible format
    //...
    //...
    return myLegibleDate;
  });
return values;
}

 

I've attempted something as simple as 

var obsvDate = new Date(feature.attributes.ObsvDate);

But when I try to print obsvDate to the console -- console.log(obsvDate) -- to see what it looks like, nothing prints. Total javascript newbie so it's possible I'm just doing something stupid.

Outcomes